diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc index b011badf00f49..623e2ee6e9646 100644 --- a/gcc/cp/cp-gimplify.cc +++ b/gcc/cp/cp-gimplify.cc @@ -1470,13 +1470,19 @@ cp_fold_r (tree *stmt_p, int *walk_subtrees, void *data_) if (data->flags & ff_genericize) cp_genericize_target_expr (stmt_p); - /* Folding might replace e.g. a COND_EXPR with a TARGET_EXPR; in - that case, strip it in favor of this one. */ if (tree &init = TARGET_EXPR_INITIAL (stmt)) { cp_walk_tree (&init, cp_fold_r, data, NULL); cp_walk_tree (&TARGET_EXPR_CLEANUP (stmt), cp_fold_r, data, NULL); *walk_subtrees = 0; + if (!flag_no_inline) + { + tree folded = maybe_constant_init (init, TARGET_EXPR_SLOT (stmt)); + if (folded != init && TREE_CONSTANT (folded)) + init = folded; + } + /* Folding might replace e.g. a COND_EXPR with a TARGET_EXPR; in + that case, strip it in favor of this one. */ if (TREE_CODE (init) == TARGET_EXPR) { tree sub = TARGET_EXPR_INITIAL (init); diff --git a/gcc/testsuite/g++.dg/analyzer/pr97116.C b/gcc/testsuite/g++.dg/analyzer/pr97116.C index d8e08a73172df..1c404c2ceb233 100644 --- a/gcc/testsuite/g++.dg/analyzer/pr97116.C +++ b/gcc/testsuite/g++.dg/analyzer/pr97116.C @@ -16,7 +16,7 @@ struct foo void test_1 (void) { foo *p = new(NULL) foo (42); // { dg-warning "non-null expected" "warning" } - // { dg-message "argument 'this' \\(\[^\n\]*\\) NULL where non-null expected" "final event" { target *-*-* } .-1 } + // { dg-message "argument 'this'( \\(\[^\n\]*\\))? NULL where non-null expected" "final event" { target *-*-* } .-1 } } int test_2 (void) diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-prvalue1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-prvalue1.C new file mode 100644 index 0000000000000..f09088d41e804 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-prvalue1.C @@ -0,0 +1,24 @@ +// PR c++/116416 +// { dg-do compile { target c++11 } } +// { dg-options "-O" } + +struct optional { + constexpr optional(int) {} +}; +optional foo() { return 2; } + + +struct C { + constexpr C(int) {} +}; + +struct B { + C fn(int) { return 0; } +}; + +void +g () +{ + B b; + b.fn(0); +} diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-prvalue1.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-prvalue1.C new file mode 100644 index 0000000000000..ad31e30011675 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-prvalue1.C @@ -0,0 +1,30 @@ +// PR c++/116416 +// { dg-do compile { target c++14 } } +// { dg-options "-O" } + +struct Str { + constexpr Str() {} + constexpr Str(const char *instr) { + str = instr; length = 0; + for (auto index = 0; instr[index]; ++index) { + ++length; + } + } + const char *str = nullptr; + int length = 0; +}; +extern void callback(Str str); +void +func1() +{ + callback(Str{"Test"}); +} +void +func2() +{ + Str str{"Test"}; + callback(str); +} + +// Check that we don't call Str::Str(char const*) +// { dg-final { scan-assembler-not "_ZN3StrC1EPKc" } } diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr78687.C b/gcc/testsuite/g++.dg/tree-ssa/pr78687.C index 698458f0e9a5f..6e8a5b7efdf93 100644 --- a/gcc/testsuite/g++.dg/tree-ssa/pr78687.C +++ b/gcc/testsuite/g++.dg/tree-ssa/pr78687.C @@ -480,4 +480,5 @@ int main(int argc, char* argv[]) f(); } -/* { dg-final { scan-tree-dump "Removing load:.*ptr;" "sra" } } */ +// XFAILed due to PR116416 +/* { dg-final { scan-tree-dump "Removing load:.*ptr;" "sra" { xfail { *-*-* } } } } */ diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr90883.C b/gcc/testsuite/g++.dg/tree-ssa/pr90883.C index 37df17d0b1668..ad9231eaff24b 100644 --- a/gcc/testsuite/g++.dg/tree-ssa/pr90883.C +++ b/gcc/testsuite/g++.dg/tree-ssa/pr90883.C @@ -16,5 +16,5 @@ // We want to match enough here to capture that we deleted an empty // constructor store // mips will expand to loop to clear because CLEAR_RATIO. -// { dg-final { scan-tree-dump "Deleted redundant store: .*\.a = {}" "dse1" { xfail { mips*-*-* } } } } - +// { dg-final { scan-tree-dump-not ".*\.a = {}" "dse1" { xfail { mips*-*-* } } } } +// { dg-final { scan-tree-dump-not ".*\.b = 0" "dse1" { xfail { mips*-*-* } } } }