diff options
author | Marek Polacek <polacek@redhat.com> | 2020-06-16 13:02:23 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2020-06-16 13:08:57 -0400 |
commit | 2661635323bd44410f1a154683eccecd2c163b46 (patch) | |
tree | 615689aa0a6b034cbb0fbfc0cd3973d2e3961ff6 /gcc | |
parent | 43a9b25c17d264b81832e3bc09135f736c9e42ec (diff) | |
download | gcc-2661635323bd44410f1a154683eccecd2c163b46.zip gcc-2661635323bd44410f1a154683eccecd2c163b46.tar.gz gcc-2661635323bd44410f1a154683eccecd2c163b46.tar.bz2 |
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-local-3.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/name-lookup.c | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Wshadow-local-3.C | 7 |
2 files changed, 10 insertions, 1 deletions
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 2ff85f1..159c98a 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -2762,7 +2762,9 @@ check_local_shadow (tree decl) enum opt_code warning_code; if (warn_shadow) warning_code = OPT_Wshadow; - else if (same_type_p (TREE_TYPE (old), TREE_TYPE (decl)) + else if ((TREE_TYPE (old) + && TREE_TYPE (decl) + && same_type_p (TREE_TYPE (old), TREE_TYPE (decl))) || TREE_CODE (decl) == TYPE_DECL || TREE_CODE (old) == TYPE_DECL || (!dependent_type_p (TREE_TYPE (decl)) diff --git a/gcc/testsuite/g++.dg/warn/Wshadow-local-3.C b/gcc/testsuite/g++.dg/warn/Wshadow-local-3.C new file mode 100644 index 0000000..fd743ec --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wshadow-local-3.C @@ -0,0 +1,7 @@ +// PR c++/95560 +// { dg-do compile { target c++11 } } + +template <typename> void fn1() { + bool ready; + enum class State { ready }; +} |