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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Reduced:

#define assert(C) if (!(C)) { __builtin_puts("Assertion failed: " #C);
__builtin_abort(); }

struct X {
  X() { }
  X(const X&) { }
};

struct A
{
  operator const X&() const
  {
    return a_;
  }

  X a_;
};

int main()
{
  A a {};

  const auto& b1 {static_cast<const X&>(a)};
  const X& b2 {a};

  assert(&a.a_ == &b1);
  assert(&b1 == &b2);  // does not work with gcc 8.3.0 any standard
}

Assertion failed: &b1 == &b2
Aborted (core dumped)

If "const X& b2 (a)" is used instead of list-init, the second assertion passes.

Reply via email to