From 070a0b6392d682f11ca79d22ae00bc822332cdcf Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Fri, 27 Mar 2020 13:13:39 -0700 Subject: [PATCH] c++: Fix ICE popping local scope [pr84733] PR c++/84733 * name-lookup.c (do_pushdecl): Look through cleanp levels. --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/name-lookup.c | 3 ++- gcc/testsuite/g++.dg/lookup/pr84733.C | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/lookup/pr84733.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8edc445e70e9..91c01f543a55 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2020-03-27 Nathan Sidwell + + PR c++/84733 + * name-lookup.c (do_pushdecl): Look through cleanp levels. + 2020-03-14 Jason Merrill PR c++/92909 diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 8999c5ad4a74..8298ee171e0a 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -2988,7 +2988,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 a/gcc/testsuite/g++.dg/lookup/pr84733.C b/gcc/testsuite/g++.dg/lookup/pr84733.C new file mode 100644 index 000000000000..d0394eab8911 --- /dev/null +++ b/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; +} -- 2.47.3