From 78ddb56a93b615b1474df4f08d358640a0736f61 Mon Sep 17 00:00:00 2001 From: Dodji Seketeli Date: Tue, 8 Mar 2011 21:14:18 +0000 Subject: [PATCH] re PR c++/47957 (Type mismatch when a class derived a same name with template parameter) 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: r170790 --- gcc/cp/ChangeLog | 5 ++++ gcc/cp/name-lookup.c | 11 ++++++-- gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/g++.dg/lookup/template3.C | 35 +++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/lookup/template3.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ad18404d0da2..1a8111a1ca9c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2011-03-08 Dodji Seketeli + + * name-lookup.c (binding_to_template_parms_of_scope_p): Only + consider scopes of primary template definitions. Adjust comments. + 2011-03-08 Jason Merrill PR c++/47488 diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index b0ea1c8040e6..924eed819538 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -4067,8 +4067,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, @@ -4084,6 +4089,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)))); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a8ba80edfbd8..87657645de8f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-03-08 Dodji Seketeli + + * g++.dg/lookup/template3.C: New test. + 2011-03-08 Richard Guenther Backport from mainline diff --git a/gcc/testsuite/g++.dg/lookup/template3.C b/gcc/testsuite/g++.dg/lookup/template3.C new file mode 100644 index 000000000000..e5f6f18edc7d --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/template3.C @@ -0,0 +1,35 @@ +// Origin PR c++/47957 +// { dg-do compile } + +struct S +{ + int m; + + S() + : m(0) + { + } +}; + +struct Base +{ + typedef S T; +}; + +template +struct Derived : public Base +{ + int + foo() + { + T a; // This is Base::T, not the template parameter. + return a.m; + } +}; + +int +main() +{ + Derived d; + return d.foo(); +} -- 2.47.2