diff options
author | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 1998-04-01 16:27:24 +0000 |
---|---|---|
committer | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 1998-04-01 16:27:24 +0000 |
commit | a6cbda882857896c0595fb13e82328a4a890cf27 (patch) | |
tree | 1827084179aea726791cfee72adc008fb5569df5 /gcc | |
parent | 16f18c1bf41575b2b37e1e5d74aef4902fff5f31 (diff) | |
download | gcc-a6cbda882857896c0595fb13e82328a4a890cf27.tar.gz |
* call.c (build_over_call): Do name resolution for default
arguments of function templates in the scope of the templates.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@18932 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/call.c | 23 | ||||
-rw-r--r-- | gcc/testsuite/g++.old-deja/g++.pt/defarg4.C | 32 |
3 files changed, 57 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 06f1bb034ca..7d96732b377 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +Wed Apr 1 14:58:35 1998 Mark Mitchell <mmitchell@usa.net> + + * call.c (build_over_call): Do name resolution for default + arguments of function templates in the scope of the templates. + Tue Mar 31 13:43:57 1998 Jeffrey A Law (law@cygnus.com) * call.c: Include system.h. Remove includes, declarations and diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 2959fc26611..ab3e05ef196 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -3220,9 +3220,26 @@ build_over_call (fn, convs, args, flags) tree arg = TREE_PURPOSE (parm); if (DECL_TEMPLATE_INFO (fn)) - /* This came from a template. Instantiate the default arg here, - not in tsubst. */ - arg = tsubst_expr (arg, DECL_TI_ARGS (fn), NULL_TREE); + { + /* This came from a template. Instantiate the default arg here, + not in tsubst. In the case of something like: + + template <class T> + struct S { + static T t(); + void f(T = t()); + }; + + we must be careful to do name lookup in the scope of + S<T>, rather than in the current class. */ + if (DECL_REAL_CONTEXT (fn)) + pushclass (DECL_REAL_CONTEXT (fn), 2); + + arg = tsubst_expr (arg, DECL_TI_ARGS (fn), NULL_TREE); + + if (DECL_REAL_CONTEXT (fn)) + popclass (0); + } converted_args = expr_tree_cons (NULL_TREE, convert_default_arg (TREE_VALUE (parm), arg), converted_args); diff --git a/gcc/testsuite/g++.old-deja/g++.pt/defarg4.C b/gcc/testsuite/g++.old-deja/g++.pt/defarg4.C new file mode 100644 index 00000000000..9d5df8cf2a3 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.pt/defarg4.C @@ -0,0 +1,32 @@ +// Build don't link: + +template <class T> +struct S1 +{ + void foo(T = t()); + + static T t(); +}; + + +template <class T> +struct S2 +{ + void bar(); +}; + + +template <class T> +void S2<T>::bar () +{ + S1<T> st; + st.foo(); +} + + +int main() +{ + S2<int> s2i; + s2i.bar(); +} + |