[PATCH c++/86881] -Wshadow-local-compatible ICE
authorNathan Sidwell <nathan@acm.org>
Tue, 18 Sep 2018 13:52:30 +0000 (13:52 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Tue, 18 Sep 2018 13:52:30 +0000 (13:52 +0000)
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.

From-SVN: r264391

gcc/cp/ChangeLog
gcc/cp/name-lookup.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/pr86881.C [new file with mode: 0644]

index cec08bfd712ca4496d6f3e1f7d91d9fcfdd17d54..f73ea2a1f3eb4b72b0740023dce12425b4d5dac3 100644 (file)
@@ -1,3 +1,8 @@
+2018-09-18  Nathan Sidwell  <nathan@acm.org>
+
+       PR c++/86881
+       * name-lookup.c (check_local_shadow): Ignore auto types.
+
 2018-09-17  David Malcolm  <dmalcolm@redhat.com>
 
        * error.c (range_label_for_type_mismatch::get_text): Update for
index bb0a70e1877923d0f24fffb9d880c2426060bb97..c56bfe58a1999c106a38382f848e8a39fb3f35c5 100644 (file)
@@ -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;
index 6b41c6800d7877978f20bd3ce2ed8cbc534ba26e..d1bc09f618b522357499e3e0b40dbcb5b7adb5a1 100644 (file)
@@ -1,3 +1,8 @@
+2018-09-18  Nathan Sidwell  <nathan@acm.org>
+
+       PR c++/86881
+       * g++.dg/warn/pr86881.C: New.
+
 2018-09-18  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
     * 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 (file)
index 0000000..4fc8d56
--- /dev/null
@@ -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 *-*-* } }
+  };
+}