diff mbox series

[C++,PR/84733] ICE popping local binding

Message ID a6e3924e-5ee8-e5c2-9d03-efd1e190cae0@acm.org
State New
Headers show
Series [C++,PR/84733] ICE popping local binding | expand

Commit Message

Nathan Sidwell March 27, 2020, 7:25 p.m. UTC
We were pushing the variable 'e' into the cleanup pseudo-binding left by 
the try/catch block, but seeing past that for the implicit type decl for 
the structure 'e'.  this bug seems to happen as far back as I can try -- 
gcc 6 at least.  Fixed by looking through the cleanup binding in both cases.

nathan
diff mbox series

Patch

2020-03-27  Nathan Sidwell  <nathan@acm.org>

	PR c++/84733
	* name-lookup.c (do_pushdecl): Look through cleanp levels.

diff --git c/gcc/cp/name-lookup.c w/gcc/cp/name-lookup.c
index e6dfb9cc723..8dd0b0d723e 100644
--- c/gcc/cp/name-lookup.c
+++ w/gcc/cp/name-lookup.c
@@ -2998,7 +2998,8 @@  do_pushdecl (tree decl, bool is_friend)
   /* The binding level we will be pushing into.  During local class
      pushing, we want to push to the containing scope.  */
   cp_binding_level *level = current_binding_level;
-  while (level->kind == sk_class)
+  while (level->kind == sk_class
+	 || level->kind == sk_cleanup)
     level = level->level_chain;
 
   /* An anonymous namespace has a NULL DECL_NAME, but we still want to
diff --git c/gcc/testsuite/g++.dg/lookup/pr84733.C w/gcc/testsuite/g++.dg/lookup/pr84733.C
new file mode 100644
index 00000000000..d0394eab891
--- /dev/null
+++ w/gcc/testsuite/g++.dg/lookup/pr84733.C
@@ -0,0 +1,21 @@ 
+// { dg-do compile { target c++11 } }
+// PR c++/84733 ICE popping local binding after cleanup region
+
+struct c {
+  ~c();
+} b;
+
+void f() {
+#ifndef OK
+  try {
+  d:
+    ;
+  } catch (int) {
+  }
+#endif
+  decltype(b) a;
+  int e;
+  struct e { } f;
+  e = 5;
+  struct e j;
+}