From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A273B3857730; Fri, 26 May 2023 17:02:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A273B3857730 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685120569; bh=1AU9Kot4MnRUw4IH66OR5+EE0+Bjl37xWeVya2BqhJo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=EX0zrEdP0jKjzPLpCxk2XVrs7IsemDOByQ0UoQEUfnHtTfGZ4Xen8kokyKM+gvPDD e4P7F3QDxX2Dy+KzfykMzna63X3I81d6ABmrJHwRQHihj8gLZ9z2oAWC78lonh5DoH uY3kYbvSQzTj3SSTxlF5srp4BH2ip42q+Go/GGZY= From: "mpolacek at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109876] [10/11/12/13/14 Regression] initializer_list not usable in constant expressions in a template Date: Fri, 26 May 2023 17:02:46 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: mpolacek at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: mpolacek at gcc dot gnu.org X-Bugzilla-Target-Milestone: 10.5 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: 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 --- Comment #10 from Marek Polacek --- So I have --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -27969,6 +27969,13 @@ value_dependent_expression_p (tree expression) else if (TYPE_REF_P (TREE_TYPE (expression))) /* FIXME cp_finish_decl doesn't fold reference initializers. */ return true; + /* We have a constexpr variable and we're processing a template. Wh= en + there's lifetime extension involved (for which finish_compound_literal + used to create a temporary), we'll not be able to evaluate the + variable until instantiating, so pretend it's value-dependent. */ + else if (DECL_DECLARED_CONSTEXPR_P (expression) + && !TREE_CONSTANT (expression)) + return true; return false; case DYNAMIC_CAST_EXPR: but that breaks struct foo { }; template void fnc() { }=20 void test() { static constexpr foo a; fnc(); } with: $ ./cc1plus -quiet nontype-auto16.C=20 nontype-auto16.C:6:31: warning: =E2=80=98void fnc() [with const foo& F =3D = a]=E2=80=99 used but never defined 6 | template void fnc() { } | ^~~ nontype-auto16.C:13:1: internal compiler error: Segmentation fault 13 | } | ^ 0x19a5624 crash_signal /home/mpolacek/src/gcc/gcc/toplev.cc:314 0x7fe161facb1f ??? =20=20=20=20=20=20=20 /usr/src/debug/glibc-2.36-9.fc37.x86_64/signal/../sysdeps/unix/sysv/linux/x= 86_64/libc_sigaction.c:0 0xcbfe74 tree_check(tree_node const*, char const*, int, char const*, tree_c= ode) /home/mpolacek/src/gcc/gcc/tree.h:3795 0x12c2224 symbol_table::decl_assembler_name_hash(tree_node const*) /home/mpolacek/src/gcc/gcc/symtab.cc:84 The warning is obviously wrong and the cause for the ICE, I'd say. test is= n't a function template but uses_template_parms / verify_unstripped_args set p_= t_d, so we still reach the new code.=