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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Without -flto, the testcase can't be linked:
./cc1plus -quiet -std=c++23 stmtexpr19.C; g++ -o stmtexpr19{,.s}
/usr/bin/ld: /tmp/ccUo7FRx.o:(.rodata+0x0): undefined reference to
`setup()::inner'
collect2: error: ld returned 1 exit status

On the other side, when static constexpr vars are defined inside of constexpr
functions or even consteval functions, it works ok:

extern "C" void abort ();

constexpr const int *
foo ()
{
  static constexpr int a = 1;
  return &a;
}

consteval const int *
bar ()
{
  static constexpr int a = 1;
  return &a;
}

[[gnu::noipa]] void
baz (const int *x)
{
  if (*x != 1)
    abort ();
}

int
main ()
{
  constexpr const int *p = foo ();
  constexpr const int *q = bar ();
  baz (p);
  baz (q);
  if (p == q)
    abort ();
}

Reply via email to