aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2021-04-16 09:32:44 +0200
committerJakub Jelinek <jakub@redhat.com>2021-04-16 09:32:44 +0200
commit20eb7a1891cfd7fa85295a236cebe0322d041edd (patch)
tree8295c3ebe8356c2f3cb3b7fefb7c290f811dc355 /gcc/cp
parent76c7e7d6b003a17d183d0571bf9b34c691819d25 (diff)
downloadgcc-20eb7a1891cfd7fa85295a236cebe0322d041edd.zip
gcc-20eb7a1891cfd7fa85295a236cebe0322d041edd.tar.gz
gcc-20eb7a1891cfd7fa85295a236cebe0322d041edd.tar.bz2
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 <jakub@redhat.com> 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. * g++.dg/cpp2a/pr99833.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/pt.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index a0ca65c..19fdafa 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -12830,7 +12830,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_CODE (*tp) == LAMBDA_EXPR)
{
/* Since we defer implicit capture, look in the parms and body. */