aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2019-01-17 15:36:31 -0500
committerJason Merrill <jason@gcc.gnu.org>2019-01-17 15:36:31 -0500
commitf18aa3a4078f83540903c5d1f5c4ad0e25597ab1 (patch)
tree5a6852032534ed4ce9f9e1915acde44e905f4037 /gcc
parentba29ed0f57b5005586e49d40aaec55d943caff61 (diff)
downloadgcc-f18aa3a4078f83540903c5d1f5c4ad0e25597ab1.zip
gcc-f18aa3a4078f83540903c5d1f5c4ad0e25597ab1.tar.gz
gcc-f18aa3a4078f83540903c5d1f5c4ad0e25597ab1.tar.bz2
PR c++/86740, ICE with constexpr if and nested generic lambdas.
When we partially instantiate the constexpr if, we walk through its body to see what it uses from the enclosing local_specializations. That walk was overlooking the use of 'count' in the captures of the innermost lambda, because we weren't walking into the capture list. * tree.c (cp_walk_subtrees): Handle LAMBDA_EXPR. From-SVN: r268046
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/tree.c8
-rw-r--r--gcc/testsuite/g++.dg/cpp1z/constexpr-if25.C27
3 files changed, 40 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 05e8566..01a5760 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2019-01-17 Jason Merrill <jason@redhat.com>
+
+ PR c++/86740, ICE with constexpr if and nested generic lambdas.
+ * tree.c (cp_walk_subtrees): Handle LAMBDA_EXPR.
+
2019-01-17 Paolo Carlini <paolo.carlini@oracle.com>
* decl.c (grokdeclarator): Use typespec_loc in error messages
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 5000216..be33d41 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -4933,6 +4933,14 @@ cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func,
}
break;
+ case LAMBDA_EXPR:
+ /* Don't walk into the body of the lambda, but the capture initializers
+ are part of the enclosing context. */
+ for (tree cap = LAMBDA_EXPR_CAPTURE_LIST (*tp); cap;
+ cap = TREE_CHAIN (cap))
+ WALK_SUBTREE (TREE_VALUE (cap));
+ break;
+
default:
return NULL_TREE;
}
diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if25.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if25.C
new file mode 100644
index 0000000..144139e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if25.C
@@ -0,0 +1,27 @@
+// PR c++/86740
+// { dg-do compile { target c++17 } }
+
+struct Constant
+{
+ static constexpr int value = 0;
+};
+template<typename F>
+void invokeWithConstant(F &&f)
+{
+ f(Constant{});
+}
+int foo()
+{
+ int count = 0;
+ invokeWithConstant
+ ([&] (auto id1)
+ {
+ invokeWithConstant
+ ([&] (auto id2)
+ {
+ if constexpr (id1.value == 0 && id2.value == 0)
+ [&] { count = 1; } ();
+ });
+ });
+ return count;
+}