From ff92beb8749a0ce0bbf5ae91ac9a9fb0287696a5 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 18 Sep 2018 13:52:30 +0000 Subject: [PATCH] [PATCH c++/86881] -Wshadow-local-compatible ICE https://gcc.gnu.org/ml/gcc-patches/2018-09/msg00984.html PR c++/86881 cp/ * name-lookup.c (check_local_shadow): Ignore auto types. testsuite/ * g++.dg/warn/pr86881.C: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@264391 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/name-lookup.c | 7 +++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/warn/pr86881.C | 20 ++++++++++++++++++++ 4 files changed, 37 insertions(+) create mode 100644 gcc/testsuite/g++.dg/warn/pr86881.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index cec08bfd712..f73ea2a1f3e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2018-09-18 Nathan Sidwell + + PR c++/86881 + * name-lookup.c (check_local_shadow): Ignore auto types. + 2018-09-17 David Malcolm * error.c (range_label_for_type_mismatch::get_text): Update for diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index bb0a70e1877..c56bfe58a19 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -2764,6 +2764,13 @@ check_local_shadow (tree 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 + its type (the old type cannot be using auto + at this point, without also being + dependent). This is an indication we're + (now) doing the shadow checking too + early. */ + && !type_uses_auto (TREE_TYPE (decl)) && can_convert (TREE_TYPE (old), TREE_TYPE (decl), tf_none)))) warning_code = OPT_Wshadow_compatible_local; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6b41c6800d7..d1bc09f618b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-09-18 Nathan Sidwell + + PR c++/86881 + * g++.dg/warn/pr86881.C: New. + 2018-09-18 Kyrylo Tkachov * gcc.target/aarch64/spellcheck_1.c: diff --git a/gcc/testsuite/g++.dg/warn/pr86881.C b/gcc/testsuite/g++.dg/warn/pr86881.C new file mode 100644 index 00000000000..4fc8d56881e --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr86881.C @@ -0,0 +1,20 @@ +// PR c++/86881 ICE with shadow warning +// { dg-do compile { c++11 } } +// { dg-additional-options { -Wshadow-compatible-local } }} + +void a() { + auto b([] {}); + { + auto b = 0; + } +} + +struct Proxy { }; + +void Two () +{ + auto my = Proxy (); + { + auto my = Proxy (); // { dg-warning "shadows" "" { xfail *-*-* } } + }; +} -- 2.11.4.GIT