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

Charlie Qiu <longfeiqiu2012 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |longfeiqiu2012 at gmail dot com

--- Comment #4 from Charlie Qiu <longfeiqiu2012 at gmail dot com> ---
I hit on the same bug when trying to implement something similar.
Here's a further simplified testcase that does not involve dynamic allocation:

struct A;

struct B { A * ptr; constexpr B () : ptr (nullptr) { } };

struct A {
  B * ptr;
  unsigned int data;

  constexpr A (B& b) { b.ptr = this; ptr = &b; }

  constexpr A (A&& other) { ptr = other.ptr; ptr->ptr = this; }
};

constexpr A f (B& b) {
  A a (b);
  return a;
}

consteval bool should_return_true () {
  B b;
  A a = f(b);
  /* At this point, b.ptr should point to a */
  b.ptr->data = 42;
  return a.data == 42;
}

int main () {
  return should_return_true ();
}

Confirmed working on Clang >= 17, not working on any version of GCC.

Reply via email to