From 59581da6977aeae5819b43ebdd1eed1ee7f0d514 Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Wed, 1 Apr 1998 16:27:24 +0000 Subject: [PATCH] call.c (build_over_call): Do name resolution for default arguments of function templates in the scope of... * call.c (build_over_call): Do name resolution for default arguments of function templates in the scope of the templates. From-SVN: r18932 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/call.c | 23 ++++++++++++++++++--- gcc/testsuite/g++.old-deja/g++.pt/defarg4.C | 32 +++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.old-deja/g++.pt/defarg4.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 06f1bb0..7d96732 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +Wed Apr 1 14:58:35 1998 Mark Mitchell + + * 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 2959fc2..ab3e05e 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 + struct S { + static T t(); + void f(T = t()); + }; + + we must be careful to do name lookup in the scope of + S, 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 0000000..9d5df8c --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.pt/defarg4.C @@ -0,0 +1,32 @@ +// Build don't link: + +template +struct S1 +{ + void foo(T = t()); + + static T t(); +}; + + +template +struct S2 +{ + void bar(); +}; + + +template +void S2::bar () +{ + S1 st; + st.foo(); +} + + +int main() +{ + S2 s2i; + s2i.bar(); +} + -- 2.7.4