re PR c++/47957 (Type mismatch when a class derived a same name with template parameter)
authorDodji Seketeli <dodji@redhat.com>
Tue, 8 Mar 2011 15:38:30 +0000 (15:38 +0000)
committerDodji Seketeli <dodji@gcc.gnu.org>
Tue, 8 Mar 2011 15:38:30 +0000 (16:38 +0100)
PR c++/47957

gcc/cp/

* name-lookup.c (binding_to_template_parms_of_scope_p): Only
consider scopes of primary template definitions.  Adjust comments.

gcc/testsuite/

* g++.dg/lookup/template3.C: New test.

From-SVN: r170779

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

index f18ce9cc2157036fa233f26f72f1df0a844810e5..df362b2953822c31b1e3d62f4b14759a1a990d2a 100644 (file)
@@ -1,3 +1,8 @@
+2011-03-08  Dodji Seketeli  <dodji@redhat.com>
+
+       * name-lookup.c (binding_to_template_parms_of_scope_p): Only
+       consider scopes of primary template definitions.  Adjust comments.
+
 2011-03-07  Jason Merrill  <jason@redhat.com>
 
        PR c++/48003
index 4117202351dfc6d488732257aa23f589376ce085..18e34417b26e2756f0679e34399ee2a65bf8d652 100644 (file)
@@ -4205,8 +4205,13 @@ qualified_lookup_using_namespace (tree name, tree scope,
 }
 
 /* Subroutine of outer_binding.
-   Returns TRUE if BINDING is a binding to a template parameter of SCOPE,
-   FALSE otherwise.  */
+
+   Returns TRUE if BINDING is a binding to a template parameter of
+   SCOPE.  In that case SCOPE is the scope of a primary template
+   parameter -- in the sense of G++, i.e, a template that has its own
+   template header.
+
+   Returns FALSE otherwise.  */
 
 static bool
 binding_to_template_parms_of_scope_p (cxx_binding *binding,
@@ -4222,6 +4227,8 @@ binding_to_template_parms_of_scope_p (cxx_binding *binding,
   return (scope
          && scope->this_entity
          && get_template_info (scope->this_entity)
+         && PRIMARY_TEMPLATE_P (TI_TEMPLATE
+                                (get_template_info (scope->this_entity)))
          && parameter_of_template_p (binding_value,
                                      TI_TEMPLATE (get_template_info \
                                                    (scope->this_entity))));
index 8eade3c5d110b161d734ccb18b0be903dd4b2d52..a2ed5fd398f315deb579c70265ca44e7e87bd095 100644 (file)
@@ -1,3 +1,7 @@
+2011-03-08  Dodji Seketeli  <dodji@redhat.com>
+
+       * g++.dg/lookup/template3.C: New test.
+
 2011-03-08  Kai Tietz  <ktietz@redhat.com>
 
        * g++.dg/tree-ssa/pr21082.C: Use __INTPTR_TYPE__ instead of
diff --git a/gcc/testsuite/g++.dg/lookup/template3.C b/gcc/testsuite/g++.dg/lookup/template3.C
new file mode 100644 (file)
index 0000000..e5f6f18
--- /dev/null
@@ -0,0 +1,35 @@
+// Origin PR c++/47957
+// { dg-do compile }
+
+struct S
+{
+  int m;
+
+  S()
+    : m(0)
+  {
+  }
+};
+
+struct Base
+{
+  typedef S T;
+};
+
+template<class T>
+struct Derived : public Base
+{
+  int
+  foo()
+  {
+    T a; // This is Base::T, not the template parameter.
+    return a.m;
+  }
+};
+
+int
+main()
+{
+  Derived<char> d;
+  return d.foo();
+}