From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id AA511385783F; Tue, 16 May 2023 18:33:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AA511385783F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684262024; bh=jr58UjvAHaI4m7xYY78eWQAWocLm3sDqBrdHufJQd9k=; h=From:To:Subject:Date:From; b=aVB94ozMHx9cGkP9m1UXQrxI4yNlggDzIPe0V9O7u+XDccSCSgsNGzPNb98c6uhgO S9GDIhZlFTr1u8hoBn9owfPZHptWa7Yuxaq4oosxJIjZjEU63K2r5cbV4b/63QtASl VEftZtede1VA8/LXbUT1HsYqMgQEIunzG14RPw3k= From: "barry.revzin at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109876] New: initializer_list not usable in constant expressions in a template Date: Tue, 16 May 2023 18:33:44 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: barry.revzin at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109876 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 template struct Array { }; #ifdef USE_TEMPLATE template #endif struct Foo { static constexpr std::initializer_list num =3D { 1, 2 }; Array 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: :15:17: in 'constexpr' expansion of 'Foo::num.std::initializer_list::size()' :15:19: error: the value of 'Foo::num' is not usable in a consta= nt expression 15 | Array 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.=