public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/112590] New: structural constexpr class fails to instantiate
@ 2023-11-17 15:26 janezz55 at gmail dot com
  2023-11-17 17:46 ` [Bug c++/112590] " mital at mitalashok dot co.uk
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: janezz55 at gmail dot com @ 2023-11-17 15:26 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-11-17 19:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-17 15:26 [Bug c++/112590] New: structural constexpr class fails to instantiate janezz55 at gmail dot com
2023-11-17 17:46 ` [Bug c++/112590] " mital at mitalashok dot co.uk
2023-11-17 18:42 ` janezz55 at gmail dot com
2023-11-17 19:26 ` janezz55 at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).