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

Arthur O'Dwyer <arthur.j.odwyer at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |arthur.j.odwyer at gmail dot 
com

--- Comment #2 from Arthur O'Dwyer <arthur.j.odwyer at gmail dot com> ---
I believe what I'm going to say is simply a duplicate of Davis's report, but
just in case it's different, I'll add mine here. This is a slightly modified
version of the example from [class.copy.elision], merely modified so that g()
returns a C++17 prvalue instead of relying on NRVO/copy-elision.
Original example: https://eel.is/c++draft/class.copy.elision#2

Modified example:

// https://godbolt.org/z/n43jPs1Kj
struct A {
  void *p;
  constexpr A(): p(this) {}
};
constexpr A g() {
  return A();
}
constexpr A b = g();    // well-formed, b.p points to b
static_assert(b.p == &b);

MSVC and Clang accept. GCC incorrectly rejects:

<source>:11:19: error: 'A{((void*)(&<anonymous>))}' is not a constant
expression
   11 | constexpr A b = g();    // well-formed, b.p points to b
      |                   ^
<source>:12:19: error: non-constant condition for static assertion
   12 | static_assert(b.p == &b);
      |               ~~~~^~~~~

Reply via email to