public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109876] New: initializer_list not usable in constant expressions in a template
@ 2023-05-16 18:33 barry.revzin at gmail dot com
  2023-05-16 18:40 ` [Bug c++/109876] [10/11/12/13/14 Regression] " mpolacek at gcc dot gnu.org
                   ` (18 more replies)
  0 siblings, 19 replies; 20+ messages in thread
From: barry.revzin at gmail dot com @ 2023-05-16 18:33 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109876
           Summary: initializer_list not usable in constant expressions in
                    a template
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: barry.revzin at gmail dot com
  Target Milestone: ---

Consider this example:

#include <initializer_list>

template <int S>
struct Array {

};

#ifdef USE_TEMPLATE
template <int N>
#endif
struct Foo
{
  static constexpr std::initializer_list<int> num = { 1, 2 };

  Array<num.size()> ctx;

};

#ifdef USE_TEMPLATE
void f(Foo<5>) { }
#else
void f(Foo) { }
#endif

In all recent versions of gcc, compiling with -DUSE_TEMPLATE fails with an
error like:

<source>:15:17:   in 'constexpr' expansion of
'Foo<N>::num.std::initializer_list<int>::size()'
<source>:15:19: error: the value of 'Foo<N>::num' is not usable in a constant
expression
   15 |   Array<num.size()> ctx;
      |                   ^

This used to work in gcc 7 and gcc 8 (except 8.1), and I don't think there's
anything about Foo being a template that should prevent this from working. The
non-template case works on all gcc versions I've tried.

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

end of thread, other threads:[~2023-12-12  0:39 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-16 18:33 [Bug c++/109876] New: initializer_list not usable in constant expressions in a template barry.revzin at gmail dot com
2023-05-16 18:40 ` [Bug c++/109876] [10/11/12/13/14 Regression] " mpolacek at gcc dot gnu.org
2023-05-16 18:43 ` pinskia at gcc dot gnu.org
2023-05-16 18:45 ` mpolacek at gcc dot gnu.org
2023-05-16 18:46 ` pinskia at gcc dot gnu.org
2023-05-16 19:13 ` mpolacek at gcc dot gnu.org
2023-05-18 16:41 ` mpolacek at gcc dot gnu.org
2023-05-18 17:07 ` ppalka at gcc dot gnu.org
2023-05-18 17:26 ` jason at gcc dot gnu.org
2023-05-19 21:01 ` mpolacek at gcc dot gnu.org
2023-05-24 20:20 ` mpolacek at gcc dot gnu.org
2023-05-24 20:28 ` jason at gcc dot gnu.org
2023-05-26 17:02 ` mpolacek at gcc dot gnu.org
2023-05-26 18:08 ` mpolacek at gcc dot gnu.org
2023-07-07 10:45 ` [Bug c++/109876] [11/12/13/14 " rguenth at gcc dot gnu.org
2023-07-14 17:16 ` cvs-commit at gcc dot gnu.org
2023-07-14 17:18 ` [Bug c++/109876] [11/12/13 " mpolacek at gcc dot gnu.org
2023-07-19 11:26 ` rguenth at gcc dot gnu.org
2023-12-12  0:37 ` cvs-commit at gcc dot gnu.org
2023-12-12  0:39 ` [Bug c++/109876] [11/12 " mpolacek at gcc dot gnu.org

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).