From 02f6c5b711b8188c3f49a79c730911b0bd216585 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Thu, 11 Jun 2020 17:58:21 -0400 Subject: [PATCH] c++: Fix ICE in check_local_shadow with enum [PR95560] Another indication that perhaps this warning is emitted too early. We crash because same_type_p gets a null type: we have an enumerator without a fixed underlying type and finish_enum_value_list hasn't yet run. So check if the type is null before calling same_type_p. PR c++/95560 * name-lookup.c (check_local_shadow): Check if types are non-null before calling same_type_p. * g++.dg/warn/Wshadow-compatible-local-3.C: New test. --- gcc/cp/name-lookup.c | 4 +++- gcc/testsuite/g++.dg/warn/Wshadow-compatible-local-3.C | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wshadow-compatible-local-3.C diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index f5535ba50bc0..b8eb21e0f978 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -2751,7 +2751,9 @@ check_local_shadow (tree decl) else if (warn_shadow_local) warning_code = OPT_Wshadow_local; else if (warn_shadow_compatible_local - && (same_type_p (TREE_TYPE (old), TREE_TYPE (decl)) + && ((TREE_TYPE (old) + && TREE_TYPE (decl) + && same_type_p (TREE_TYPE (old), TREE_TYPE (decl))) || (!dependent_type_p (TREE_TYPE (decl)) && !dependent_type_p (TREE_TYPE (old)) /* If the new decl uses auto, we don't yet know diff --git a/gcc/testsuite/g++.dg/warn/Wshadow-compatible-local-3.C b/gcc/testsuite/g++.dg/warn/Wshadow-compatible-local-3.C new file mode 100644 index 000000000000..045dc75563eb --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wshadow-compatible-local-3.C @@ -0,0 +1,8 @@ +// PR c++/95560 +// { dg-do compile { target c++11 } } +// { dg-options "-Wshadow=compatible-local" } + +template void fn1() { + bool ready; + enum class State { ready }; +} -- 2.47.2