From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1734) id 7B16C3858C83; Wed, 15 Mar 2023 18:28:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7B16C3858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678904904; bh=4gjkYCy1CR6UEngagnhdnt8XcFocuLPXdHY/+fZuu+k=; h=From:To:Subject:Date:From; b=k0uXCmjEAd+ETPfm03tlUb9jz4KZ/dFb0+IL7I2wox5Jo8tu+ICj9EwSiFQeYQuYu eGbFpiORC+5pSELEGGQHvQc1hnw0WLylIbG5A6RBAVFmW6j+itclXKDGYbomjUXJTl zfgU5nnqrMHgJN2fEJvfnDW3fz91TDseHgO8NGZs= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marek Polacek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-6697] c++: ICE with constexpr lambda [PR107280] X-Act-Checkin: gcc X-Git-Author: Marek Polacek X-Git-Refname: refs/heads/trunk X-Git-Oldrev: cd394c542b73cab89228f4aad7afe757e58ef126 X-Git-Newrev: be20dcc359bcc4677c5b9ce011d3cd7b4ce94a64 Message-Id: <20230315182824.7B16C3858C83@sourceware.org> Date: Wed, 15 Mar 2023 18:28:24 +0000 (GMT) List-Id: https://gcc.gnu.org/g:be20dcc359bcc4677c5b9ce011d3cd7b4ce94a64 commit r13-6697-gbe20dcc359bcc4677c5b9ce011d3cd7b4ce94a64 Author: Marek Polacek 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("")} 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. 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 8683c00596a..abf6ee560c5 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -6033,7 +6033,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 constexpr void +test () +{ + string str{}; + auto append = [&](const char *s) { *str.str = *s; }; + append(""); +} + +static_assert ((test(), true), "");