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

            Bug ID: 112590
           Summary: structural constexpr class fails to instantiate
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: janezz55 at gmail dot com
  Target Milestone: ---

Compiling:

#include <cstddef>

template <auto C> void test() {}

template <std::size_t N>
struct S
{
  int a_[N];
  int* f_;
  constexpr S(): a_{}, f_{a_} {}
};

int main()
{
  test<S<10>{}>();
  return 0;
}

fails with:

prog.cc: In function 'int main()':
prog.cc:18:16: error: no matching function for call to 'test<S<10>()>()'
   18 |   test<S<10>{}>();
      |   ~~~~~~~~~~~~~^~
prog.cc:4:6: note: candidate: 'template<auto C> void test()'
    4 | void test()
      |      ^~~~
prog.cc:4:6: note:   template argument deduction/substitution failed:
prog.cc:18:16: error: 'S<10>{int [10](), ((int*)(&<anonymous>.S<10>::a_))}' is
not a constant expression
   18 |   test<S<10>{}>();
      |   ~~~~~~~~~~~~~^~
prog.cc:18:16: error: 'S<10>()' is not a constant expression because it refers
to an incompletely initialized variable

But everything is initialized. I believe a workaround exists, but I didn't
experiment.

https://wandbox.org/permlink/xA81TIzI5XsXdh57

Reply via email to