diff mbox series

[PR,c++/82424] Dont convert dependent types

Message ID e952cbdf-3569-a495-ef45-013eaf83f96a@acm.org
State New
Headers show
Series [PR,c++/82424] Dont convert dependent types | expand

Commit Message

Nathan Sidwell Oct. 6, 2017, 3:55 p.m. UTC
This fixes crash with -Wshadow=compatible-local, where we ended up 
trying to convert to or from a dependent type.  Rather than skip that 
out right, I see if the types are the same (dependent or not) before 
also trying convert in the non-dependent case.  I suppose I could try 
matching unqualified variants, but that's probably a slippery slope.

Applying to trunk.

nathan
diff mbox series

Patch

2017-10-06  Nathan Sidwell  <nathan@acm.org>

	cp/
	PR c++/82424
	* name-lookup.c (check_local_shadow): Don't try and convert
	dependent types.

	testsuite/
	PR c++/82424
	* g++.dg/warn/pr82424.C: New.

Index: cp/name-lookup.c
===================================================================
--- cp/name-lookup.c	(revision 253493)
+++ cp/name-lookup.c	(working copy)
@@ -2728,7 +2728,11 @@  check_local_shadow (tree decl)
       else if (warn_shadow_local)
 	warning_code = OPT_Wshadow_local;
       else if (warn_shadow_compatible_local
-	       && can_convert (TREE_TYPE (old), TREE_TYPE (decl), tf_none))
+	       && (same_type_p (TREE_TYPE (old), TREE_TYPE (decl))
+		   || (!dependent_type_p (TREE_TYPE (decl))
+		       && !dependent_type_p (TREE_TYPE (old))
+		       && can_convert (TREE_TYPE (old), TREE_TYPE (decl),
+				       tf_none))))
 	warning_code = OPT_Wshadow_compatible_local;
       else
 	return;
Index: testsuite/g++.dg/warn/pr82424.C
===================================================================
--- testsuite/g++.dg/warn/pr82424.C	(revision 0)
+++ testsuite/g++.dg/warn/pr82424.C	(working copy)
@@ -0,0 +1,20 @@ 
+// { dg-additional-options "-Wshadow=compatible-local" }
+
+// pr c++/82424 we were trying to convert between dependent types.
+template <typename T> class a
+{
+  struct b;
+  template <typename, typename> void c ();
+};
+template <typename T>
+template <typename, typename>
+void
+a<T>::c ()
+{
+  typedef typename T::b b; // Don't go looking inside the typename
+  T thing;
+  {
+    T thing; // { dg-warning "shadows a previous local" }
+  }
+}
+