public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-9263] c++: ICE with constexpr lambda [PR107280]
@ 2023-03-15 18:29 Marek Polacek
  0 siblings, 0 replies; only message in thread
From: Marek Polacek @ 2023-03-15 18:29 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:a1ebe3f7f9c14e66df2ae56138c495cad33c7ee4

commit r12-9263-ga1ebe3f7f9c14e66df2ae56138c495cad33c7ee4
Author: Marek Polacek <polacek@redhat.com>
Date:   Fri Mar 10 10:14:20 2023 -0500

    c++: ICE with constexpr lambda [PR107280]
    
    We crash here since r10-3661, the store_init_value hunk in particular.
    Before, we called cp_fully_fold_init, so e.g.
    
      {.str=VIEW_CONVERT_EXPR<char[8]>("")}
    
    was folded into
    
      {.str=""}
    
    but now we don't fold and keep the VCE around, and it causes trouble in
    cxx_eval_store_expression: in the !refs->is_empty () loop we descend on
    .str's initializer but since it's wrapped in a VCE, we skip the STRING_CST
    check and then crash on the CONSTRUCTOR_NO_CLEARING.
    
            PR c++/107280
    
    gcc/cp/ChangeLog:
    
            * constexpr.cc (cxx_eval_store_expression): Strip location wrappers.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp1z/constexpr-lambda28.C: New test.
    
    (cherry picked from commit be20dcc359bcc4677c5b9ce011d3cd7b4ce94a64)

Diff:
---
 gcc/cp/constexpr.cc                             |  3 ++-
 gcc/testsuite/g++.dg/cpp1z/constexpr-lambda28.C | 15 +++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index eefcebd28c5..a67a7da31ef 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -5735,7 +5735,8 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t,
 	  *valp = build_constructor (type, NULL);
 	  CONSTRUCTOR_NO_CLEARING (*valp) = no_zero_init;
 	}
-      else if (TREE_CODE (*valp) == STRING_CST)
+      else if (STRIP_ANY_LOCATION_WRAPPER (*valp),
+	       TREE_CODE (*valp) == STRING_CST)
 	{
 	  /* An array was initialized with a string constant, and now
 	     we're writing into one of its elements.  Explode the
diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda28.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda28.C
new file mode 100644
index 00000000000..aafbfddd8b9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda28.C
@@ -0,0 +1,15 @@
+// PR c++/107280
+// { dg-do compile { target c++17 } }
+
+struct string {
+  char str[8] = "";
+};
+template <int, int> constexpr void
+test ()
+{
+  string str{};
+  auto append = [&](const char *s) { *str.str = *s; };
+  append("");
+}
+
+static_assert ((test<true, true>(), true), "");

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-15 18:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-15 18:29 [gcc r12-9263] c++: ICE with constexpr lambda [PR107280] Marek Polacek

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