public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH]  PR c++/86740, ICE with constexpr if and nested generic lambdas.
@ 2019-01-17 20:36 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2019-01-17 20:36 UTC (permalink / raw)
  To: gcc-patches

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.

Tested x86_64-pc-linux-gnu, applying to trunk.

	* tree.c (cp_walk_subtrees): Handle LAMBDA_EXPR.
---
 gcc/cp/tree.c                               |  8 ++++++
 gcc/testsuite/g++.dg/cpp1z/constexpr-if25.C | 27 +++++++++++++++++++++
 gcc/cp/ChangeLog                            |  5 ++++
 3 files changed, 40 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp1z/constexpr-if25.C

diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 50002161500..be33d4186f9 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 00000000000..144139ea196
--- /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;
+}
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 05e8566e493..01a57601f4c 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

base-commit: 7e351bf905bf4b0ad84bf9dae79032f8c41f0e03
-- 
2.20.1

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

only message in thread, other threads:[~2019-01-17 20:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-17 20:36 [C++ PATCH] PR c++/86740, ICE with constexpr if and nested generic lambdas Jason Merrill

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