diff options
author | Nathan Sidwell <nathan@codesourcery.com> | 2001-03-01 14:01:39 +0000 |
---|---|---|
committer | Nathan Sidwell <nathan@gcc.gnu.org> | 2001-03-01 14:01:39 +0000 |
commit | fbfe8c9e5ab2168a5776947525909c485afe39f3 (patch) | |
tree | a3ac89d597d4b0217d02828d183a010e6bea8ec0 /gcc | |
parent | 4d24a8896575dfb50d733d1213dbe00bb6df3ab3 (diff) | |
download | gcc-fbfe8c9e5ab2168a5776947525909c485afe39f3.zip gcc-fbfe8c9e5ab2168a5776947525909c485afe39f3.tar.gz gcc-fbfe8c9e5ab2168a5776947525909c485afe39f3.tar.bz2 |
Implement using decls inside template functions.
cp:
Implement using decls inside template functions.
* decl2.c (validate_nonmember_using_decl): Don't special case
fake_std_node in the global namespace. Don't reject early when
processing a template.
(do_local_using_decl): Add to statement tree. Don't do further
processing when building a template.
* pt.c (tsubst_expr, DECL_STMT case): Deal with USING_DECLs.
testsuite:
* g++.old-deja/g++.pt/using1.C: New test.
From-SVN: r40151
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/cp/decl2.c | 19 | ||||
-rw-r--r-- | gcc/cp/pt.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.old-deja/g++.pt/using1.C | 36 |
5 files changed, 66 insertions, 11 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c5d0c95..053c227 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,15 @@ 2001-03-01 Nathan Sidwell <nathan@codesourcery.com> + Implement using decls inside template functions. + * decl2.c (validate_nonmember_using_decl): Don't special case + fake_std_node in the global namespace. Don't reject early when + processing a template. + (do_local_using_decl): Add to statement tree. Don't do further + processing when building a template. + * pt.c (tsubst_expr, DECL_STMT case): Deal with USING_DECLs. + +2001-03-01 Nathan Sidwell <nathan@codesourcery.com> + * decl2.c (do_nonmember_using_decl): Don't complain if we find same function. Do complain about ambiguating extern "C" declarations. diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index d115dcc..000eb78 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -5032,16 +5032,6 @@ validate_nonmember_using_decl (decl, scope, name) if (TREE_CODE (decl) == SCOPE_REF && TREE_OPERAND (decl, 0) == fake_std_node) { - if (namespace_bindings_p () - && current_namespace == global_namespace) - /* There's no need for a using declaration at all, here, - since `std' is the same as `::'. We can't just pass this - on because we'll complain later about declaring something - in the same scope as a using declaration with the same - name. We return NULL_TREE which indicates to the caller - that there's no need to do any further processing. */ - return NULL_TREE; - *scope = global_namespace; *name = TREE_OPERAND (decl, 1); } @@ -5054,7 +5044,8 @@ validate_nonmember_using_decl (decl, scope, name) A using-declaration for a class member shall be a member-declaration. */ - if (TREE_CODE (*scope) != NAMESPACE_DECL) + if (!processing_template_decl + && TREE_CODE (*scope) != NAMESPACE_DECL) { if (TYPE_P (*scope)) cp_error ("`%T' is not a namespace", *scope); @@ -5212,6 +5203,12 @@ do_local_using_decl (decl) if (decl == NULL_TREE) return; + if (building_stmt_tree () + && at_function_scope_p ()) + add_decl_stmt (decl); + if (processing_template_decl) + return; + oldval = lookup_name_current_level (name); oldtype = lookup_type_current_level (name); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 331b307..0994d67 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -7299,6 +7299,14 @@ tsubst_expr (t, args, complain, in_decl) decl = DECL_STMT_DECL (t); if (TREE_CODE (decl) == LABEL_DECL) finish_label_decl (DECL_NAME (decl)); + else if (TREE_CODE (decl) == USING_DECL) + { + tree scope = DECL_INITIAL (decl); + tree name = DECL_NAME (decl); + + scope = tsubst_expr (scope, args, complain, in_decl); + do_local_using_decl (build_nt (SCOPE_REF, scope, name)); + } else { init = DECL_INITIAL (decl); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 414c253..0a1a3ec 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2001-03-01 Nathan Sidwell <nathan@codesourcery.com> + * g++.old-deja/g++.pt/using1.C: New test. + +2001-03-01 Nathan Sidwell <nathan@codesourcery.com> + * g++.old-deja/g++.other/using9.C: New test. 2001-02-28 Ovidiu Predescu <ovidiu@cup.hp.com> diff --git a/gcc/testsuite/g++.old-deja/g++.pt/using1.C b/gcc/testsuite/g++.old-deja/g++.pt/using1.C new file mode 100644 index 0000000..eca6c50 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.pt/using1.C @@ -0,0 +1,36 @@ +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 26 Feb 2001 <nathan@codesourcery.com> + +// Bug 1981. using declarations in namespace scope were not remembered. + +namespace A +{ + void swap () {} +}; + +template <class T> void f() +{ + using A::swap; +} + +template void f<float> (); + +namespace B +{ + int foo (int) { return 1;} + + template <class T> int baz () + { + using ::foo; + + return foo (1); + } + template int baz<float> (); +}; + +int foo (int) { return 0;} + +int main () +{ + return B::baz<float> (); +} |