diff options
author | Mark Mitchell <mark@markmitchell.com> | 1998-10-16 18:40:36 +0000 |
---|---|---|
committer | Mark Mitchell <mmitchel@gcc.gnu.org> | 1998-10-16 18:40:36 +0000 |
commit | 8e52e063afdb17d8d92e5ceb1c03dc915a5a17a3 (patch) | |
tree | 151b95f314a2e4005fa963c4858801aac63ccb57 /gcc | |
parent | 96b106e5c960e9aad26ee54caa0a9f1688e55b6b (diff) | |
download | gcc-8e52e063afdb17d8d92e5ceb1c03dc915a5a17a3.zip gcc-8e52e063afdb17d8d92e5ceb1c03dc915a5a17a3.tar.gz gcc-8e52e063afdb17d8d92e5ceb1c03dc915a5a17a3.tar.bz2 |
decl.c (lookup_name_real): Handle template parameters for member temlates where said parameters have the...
* decl.c (lookup_name_real): Handle template parameters for member
temlates where said parameters have the same name as the
surrounding class.
From-SVN: r23141
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/cp/decl.c | 24 | ||||
-rw-r--r-- | gcc/testsuite/g++.old-deja/g++.pt/redecl2.C | 14 |
3 files changed, 41 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 0569dd3..11159fa 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 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. + * decl.c (expand_static_init): Build cleanups before entering the anonymous function used to do them to avoid access-checking confusion. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 80ee017..1c4f12c 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5166,7 +5166,29 @@ lookup_name_real (name, prefer_type, nonclass, namespaces_only) if (locval && classval) { - if (current_scope () == current_function_decl + /* 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; diff --git a/gcc/testsuite/g++.old-deja/g++.pt/redecl2.C b/gcc/testsuite/g++.old-deja/g++.pt/redecl2.C new file mode 100644 index 0000000..0b65e1e --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.pt/redecl2.C @@ -0,0 +1,14 @@ +// Build don't link: + +struct A +{ + template <class A> + void f(A) {} +}; + +void g() +{ + A a; + a.f(3); +} + |