g++ reports an error where a program attempts to take the address of an rvalue
of built-in type, but merely warns where it takes the address of an rvalue of
user-defined type:

$ cat test.cc
int i() { return 0; }
class A {};
A a() { return A(); }
int main()
{
    int * pi = &i();
    A * pa = &a();
}
$ g++-3.4 test.cc
test.cc: In function `int main()':
test.cc:6: error: non-lvalue in unary `&'
test.cc:7: warning: taking address of temporary

The first error message is also odd; "non-lvalue" is C terminology that is
rarely used in relation to C++.

I would expect an attempt to take the address of an rvalue of any type to result
in an error; it's banned by the standard and I can't think of any useful
semantics for it if it is allowed.

-- 
           Summary: Inconsistent diagnostics for taking address of rvalue
           Product: gcc
           Version: 3.4.4
            Status: UNCONFIRMED
          Severity: minor
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: benh at bwsint dot com
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i486-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21386

Reply via email to