https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60517

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |msebor at gcc dot gnu.org
      Known to work|                            |9.1.0
         Resolution|---                         |FIXED
      Known to fail|                            |4.9.1, 5.5.0, 6.4.0, 7.4.0,
                   |                            |8.3.0

--- Comment #25 from Martin Sebor <msebor at gcc dot gnu.org> ---
GCC 9 rejects the test case with the error below:

$ cat pr60517.C && gcc -Wall -S pr60517.C
class B {
public:
    double x[2];
};
class A {
    B b;
public:
    B getB(void) { return b; }
};

double foo(A a) {
    double * x = &(a.getB().x[0]);
    return x[0];
}

pr60517.C: In function ‘double foo(A)’:
pr60517.C:12:33: error: taking address of rvalue [-fpermissive]
   12 |     double * x = &(a.getB().x[0]);
      |                                 ^

The change that introduced the error is r260621:

        CWG 616, 1213 - value category of subobject references.

        * tree.c (lvalue_kind): A reference to a subobject of a prvalue is
        an xvalue.
        * typeck2.c (build_m_component_ref): Likewise.
        * typeck.c (cp_build_addr_expr_1, lvalue_or_else): Remove diagnostic
        distinction between temporary and xvalue.

I don't see a test case for this error so let me add one and resolve the bug.

Reply via email to