This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for template parameters with same name as class
- To: egcs-patches at cygnus dot com
- Subject: C++ PATCH for template parameters with same name as class
- From: Mark Mitchell <mark at markmitchell dot com>
- Date: Fri, 16 Oct 1998 18:39:58 -0700
- Cc: Jason Merrill <jason at cygnus dot com>
- Reply-to: mark at markmitchell dot com
This a gluestick to hold some of the band-aids that are holding the
other gluesticks together in g++'s name-lookup routines.
--
Mark Mitchell mark@markmitchell.com
Mark Mitchell Consulting http://www.markmitchell.com
1998-10-16 Mark Mitchell <mark@markmitchell.com>
* decl.c (lookup_name_real): Handle template parameters for member
temlates where said parameters have the same name as the
surrounding class.
Index: testsuite/g++.old-deja/g++.pt/redecl2.C
===================================================================
RCS file: redecl2.C
diff -N redecl2.C
*** /dev/null Mon Dec 31 20:00:00 1979
--- redecl2.C Fri Oct 16 18:33:52 1998
***************
*** 0 ****
--- 1,14 ----
+ // Build don't link:
+
+ struct A
+ {
+ template <class A>
+ void f(A) {}
+ };
+
+ void g()
+ {
+ A a;
+ a.f(3);
+ }
+
Index: cp/decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.235
diff -c -p -r1.235 decl.c
*** decl.c 1998/10/16 14:06:22 1.235
--- decl.c 1998/10/17 01:34:50
*************** lookup_name_real (name, prefer_type, non
*** 5166,5172 ****
if (locval && classval)
{
! if (current_scope () == current_function_decl
&& ! hack_decl_function_context (current_function_decl))
/* Not in a nested function. */
val = locval;
--- 5166,5194 ----
if (locval && classval)
{
! /* We have both a local binding and a class-level binding. This
! can happen in two ways:
!
! o We are in a member function of a class.
! o We are in a local class within a function.
!
! We need to determine which one of these situations is
! occuring, and give the innermost binding. One tricky bit is
! that with member templates we can be in the first case
! without CURRENT_FUNCTION_DECL being set. Consider
!
! struct A { template <class A> void f(A); };
!
! Here, when we look at the `A' in the parameter declaration
! for `f' we have a local binding (the template parameter) and
! a class-level binding (the TYPE_DECL for the class).
! Fortunately, if LOCVAL is a template parameter it is safe to
! take it; nothing within the scope of the template parameter
! is allowed to have the same name. */
!
! if (decl_template_parm_p (locval))
! val = locval;
! else if (current_scope () == current_function_decl
&& ! hack_decl_function_context (current_function_decl))
/* Not in a nested function. */
val = locval;