public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "mpolacek at gcc dot gnu.org" <gcc-bugzilla@gcc.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	[thread overview]
Message-ID: <bug-109876-4-M0iuDuZF9Q@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-109876-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #10 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
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.  When
+    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 <const foo & F> void fnc() { } 

void
test()
{
  static constexpr foo a;
  fnc<a>();
}

with:

$ ./cc1plus -quiet nontype-auto16.C 
nontype-auto16.C:6:31: warning: ‘void fnc() [with const foo& F = a]’ used but
never defined
    6 | template <const foo & F> 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 ???
       
/usr/src/debug/glibc-2.36-9.fc37.x86_64/signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0xcbfe74 tree_check(tree_node const*, char const*, int, char const*, tree_code)
        /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 isn't
a function template but uses_template_parms / verify_unstripped_args set p_t_d,
so we still reach the new code.

  parent reply	other threads:[~2023-05-26 17:02 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-16 18:33 [Bug c++/109876] New: " 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-109876-4-M0iuDuZF9Q@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).