From: Christian Bruel Date: Wed, 31 Oct 2007 07:55:46 +0000 (+0100) Subject: fix PR c++/19531: NRV is performed on volatile temporary X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0e95aec103af4ec97f6d282b95882f2e0efb0b41;p=gcc.git fix PR c++/19531: NRV is performed on volatile temporary Co-Authored-By: Mark Mitchell From-SVN: r129792 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5e2447f94c3..484d15216b8 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2007-10-31 Christian Bruel + Mark Mitchell + + PR c++/19531 + * cp/typeck.c (check_return_expr): Don't set named_return_value_okay_p + if retval is volatile. + 2007-10-30 Jakub Jelinek PR c++/33616 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 392e2db3a99..c31a7a8ed45 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -6744,7 +6744,9 @@ check_return_expr (tree retval, bool *no_warning) function. */ && same_type_p ((TYPE_MAIN_VARIANT (TREE_TYPE (retval))), (TYPE_MAIN_VARIANT - (TREE_TYPE (TREE_TYPE (current_function_decl)))))); + (TREE_TYPE (TREE_TYPE (current_function_decl))))) + /* And the returned value must be non-volatile. */ + && ! TYPE_VOLATILE (TREE_TYPE (retval))); if (fn_returns_value_p && flag_elide_constructors) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 82dbb7a6715..94925829892 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-10-31 Christian Bruel + + PR c++/19531 + * g++.dg/opt/nrv8.C: New. + 2007-10-30 Jakub Jelinek PR c++/33709 diff --git a/gcc/testsuite/g++.dg/opt/nrv8.C b/gcc/testsuite/g++.dg/opt/nrv8.C new file mode 100644 index 00000000000..19999a18824 --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/nrv8.C @@ -0,0 +1,31 @@ +// PR optimization/19531 +// forbids NRV on volatile return value. +// { dg-options -O2 } +// { dg-do run } + +extern "C" { void abort(); } + +struct A +{ + int d; + + A () { d = 123; } + A (const A & o) { d = o.d; } + A (volatile const A & o) { d = o.d + 2; } +}; + +A bar() +{ + volatile A l; + return l; +} + +main() +{ + A a = bar (); + + if (a.d != 125) + abort(); + + return 0; +}