From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 3F9783A4082B; Thu, 22 Apr 2021 16:53:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F9783A4082B MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r8-10910] c++: Fix up handling of structured bindings in extract_locals_r [PR99833] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-8 X-Git-Oldrev: ecb5f4b7d68e1e5ac0482bebc886b9273ffe1527 X-Git-Newrev: 7285512d782ded76d1b0d0d164fdc1c5ab7e9fe0 Message-Id: <20210422165302.3F9783A4082B@sourceware.org> Date: Thu, 22 Apr 2021 16:53:02 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Apr 2021 16:53:02 -0000 https://gcc.gnu.org/g:7285512d782ded76d1b0d0d164fdc1c5ab7e9fe0 commit r8-10910-g7285512d782ded76d1b0d0d164fdc1c5ab7e9fe0 Author: Jakub Jelinek Date: Fri Apr 16 09:32:44 2021 +0200 c++: Fix up handling of structured bindings in extract_locals_r [PR99833] The following testcase ICEs in tsubst_decomp_names because the assumptions that the structured binding artificial var is followed in DECL_CHAIN by the corresponding structured binding vars is violated. I've tracked it to extract_locals* which is done for the constexpr IF_STMT. extract_locals_r when it sees a DECL_EXPR adds that decl into a hash set so that such decls aren't returned from extract_locals*, but in the case of a structured binding that just means the artificial var and not the vars corresponding to structured binding identifiers. The following patch fixes it by pushing not just the artificial var for structured bindings but also the other vars. 2021-04-16 Jakub Jelinek PR c++/99833 * pt.c (extract_locals_r): When handling DECL_EXPR of a structured binding, add to data.internal also all corresponding structured binding decls. * g++.dg/cpp1z/pr99833.C: New test. (cherry picked from commit 06d50ebc9fb2761ed2bdda5e76adb4d47a8ca983) Diff: --- gcc/cp/pt.c | 22 +++++++++++++++++++++- gcc/testsuite/g++.dg/cpp1z/pr99833.C | 11 +++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 7b5944d33ab..42a40bd87c7 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -12011,7 +12011,27 @@ extract_locals_r (tree *tp, int */*walk_subtrees*/, void *data_) tp = &TYPE_NAME (*tp); if (TREE_CODE (*tp) == DECL_EXPR) - data.internal.add (DECL_EXPR_DECL (*tp)); + { + tree decl = DECL_EXPR_DECL (*tp); + data.internal.add (decl); + if (VAR_P (decl) + && DECL_DECOMPOSITION_P (decl) + && TREE_TYPE (decl) != error_mark_node) + { + gcc_assert (DECL_NAME (decl) == NULL_TREE); + for (tree decl2 = DECL_CHAIN (decl); + decl2 + && VAR_P (decl2) + && DECL_DECOMPOSITION_P (decl2) + && DECL_NAME (decl2) + && TREE_TYPE (decl2) != error_mark_node; + decl2 = DECL_CHAIN (decl2)) + { + gcc_assert (DECL_DECOMP_BASE (decl2) == decl); + data.internal.add (decl2); + } + } + } else if (tree spec = retrieve_local_specialization (*tp)) { if (data.internal.contains (*tp)) diff --git a/gcc/testsuite/g++.dg/cpp1z/pr99833.C b/gcc/testsuite/g++.dg/cpp1z/pr99833.C new file mode 100644 index 00000000000..f7c995887f8 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/pr99833.C @@ -0,0 +1,11 @@ +// PR c++/99833 +// { dg-do compile { target c++17 } } + +struct S { int a, b; }; +template +void +foo () +{ + [](auto d) { if constexpr (auto [a, b]{d}; sizeof (a) > 0) a++; } (S{}); +} +template void foo ();