This ICE happens when we try and figure if an unresolved auto type is compatible with a previous binding. With the addition of auto, we're now checking too early, but that's a harder problem. This fixes the ICE, but the downside is we don't warn at all, if the auto resolves to a compatible type. But that's not a new problem.

Applying to trunk and gcc-8

nathan
--
Nathan Sidwell
2018-09-18  Nathan Sidwell  <nat...@acm.org>

	PR c++/86881
	cp/
	* name-lookup.c (check_local_shadow): Ignore auto types.

	testsuite/
	* g++.dg/warn/pr86881.C: New.

Index: gcc/cp/name-lookup.c
===================================================================
--- gcc/cp/name-lookup.c	(revision 264371)
+++ gcc/cp/name-lookup.c	(working copy)
@@ -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: gcc/testsuite/g++.dg/warn/pr86881.C
===================================================================
--- gcc/testsuite/g++.dg/warn/pr86881.C	(revision 0)
+++ gcc/testsuite/g++.dg/warn/pr86881.C	(working copy)
@@ -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 *-*-* } }
+  };
+}

Reply via email to