------- Additional Comments From aoliva at gcc dot gnu dot org 2005-03-05 14:03 ------- Subject: Re: [PR c++/20103] failure to gimplify constructors for addressable types
On Mar 5, 2005, Alexandre Oliva <[EMAIL PROTECTED]> wrote: > On Mar 4, 2005, Mark Mitchell <[EMAIL PROTECTED]> wrote: >>> + foo ((B){x}); >> I don't think (B){x} should be an lvalue, C99 notwithstanding. B(3) >> is not be an lavalue; I don't see why "(B){x}" should be. > Works for me. We can always extend it later, should the ISO C++ > committee make a decision different from ours. > Patch will follow hopefully later today. For small values of later :-) Testing now. I was a bit surprised that the casts to (const B&) weren't reported as faulty, but didn't check the standard on it. Ok to install if testing passes? Index: gcc/cp/ChangeLog from Alexandre Oliva <[EMAIL PROTECTED]> PR c++/20103 * semantics.c (finish_compound_literal): Wrap it in a target_expr. Index: gcc/cp/semantics.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v retrieving revision 1.463 diff -u -p -r1.463 semantics.c --- gcc/cp/semantics.c 23 Feb 2005 05:30:48 -0000 1.463 +++ gcc/cp/semantics.c 5 Mar 2005 13:56:17 -0000 @@ -1996,7 +1996,9 @@ finish_compound_literal (tree type, tree complete_array_type (type, compound_literal, 1); } - return compound_literal; + /* A compound-literal is an lvalue in C, but is it going to be in + ISO C++? Assume it's an rvalue for now. */ + return get_target_expr (compound_literal); } /* Return the declaration for the function-name variable indicated by Index: gcc/testsuite/ChangeLog from Alexandre Oliva <[EMAIL PROTECTED]> * g++.dg/tree-ssa/pr20103.C: New. Index: gcc/testsuite/g++.dg/tree-ssa/pr20103.C =================================================================== RCS file: gcc/testsuite/g++.dg/tree-ssa/pr20103.C diff -N gcc/testsuite/g++.dg/tree-ssa/pr20103.C --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gcc/testsuite/g++.dg/tree-ssa/pr20103.C 5 Mar 2005 13:56:31 -0000 @@ -0,0 +1,41 @@ +// PR c++/20103 + +// { dg-do compile } + +// { dg-options "" } + +// Gimplification used to fail for (B){x}, because create_tmp_var +// required a non-addressable type, and we didn't wrap the constructor +// in a target_expr, ensuring it's moved to a separate decl. + +// Whether it is an lvalue, like in C, or an rvalue, is up to the ISO +// C++ Commitete to decide in the second version of the C++ Standard. +// We're going with rvalues for now. + +struct A +{ + A(const A&); +}; + +struct B +{ + A a; +}; + +void foo(B); +void bar(B&); // { dg-error "in passing argument" } +void bac(const B&); +void bap(const B*); + +void baz(A &x) +{ + foo ((B){x}); + bar ((B){x}); // { dg-error "non-const reference" } + bac ((B){x}); + bap (&(B){x}); // { dg-error "address of temporary" } + + foo ((const B&)(B){x}); + bar ((B&)(B){x}); // { dg-error "invalid cast" } + bac ((const B&)(B){x}); + bap (&(const B&)(B){x}); +} -- Alexandre Oliva http://www.ic.unicamp.br/~oliva/ Red Hat Compiler Engineer [EMAIL PROTECTED], gcc.gnu.org} Free Software Evangelist [EMAIL PROTECTED], gnu.org} -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20103