From: Nathan Sidwell Date: Tue, 1 May 2001 12:56:12 +0000 (+0000) Subject: cp-tree.def (USING_STMT): New statement node. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9da99f7d83904a9b4b3e4479c54ecf2934f9281e;p=gcc.git cp-tree.def (USING_STMT): New statement node. cp: * cp-tree.def (USING_STMT): New statement node. * cp-tree.h (USING_STMT_NAMESPACE): New macro. * decl2.c (do_using_directive): Add USING_STMT to statement tree. Don't emit errors when processing template decl. * pt.c (tsubst_expr, USING_STMT case): New case. * semantics.c (cp_expand_stmt, USING_STMT case): New case. testsuite: * g++.old-deja/g++.ns/template17.C: New test. From-SVN: r41724 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b082ce289ac..c3b8cf0267d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2001-05-01 Nathan Sidwell + + * cp-tree.def (USING_STMT): New statement node. + * cp-tree.h (USING_STMT_NAMESPACE): New macro. + * decl2.c (do_using_directive): Add USING_STMT to statement + tree. Don't emit errors when processing template decl. + * pt.c (tsubst_expr, USING_STMT case): New case. + * semantics.c (cp_expand_stmt, USING_STMT case): New case. + 2001-05-01 Nathan Sidwell * call.c (build_new_op): Convert args from reference here. diff --git a/gcc/cp/cp-tree.def b/gcc/cp/cp-tree.def index 486667c3a80..ee104f57b0c 100644 --- a/gcc/cp/cp-tree.def +++ b/gcc/cp/cp-tree.def @@ -171,6 +171,9 @@ DEFTREECODE (TYPEOF_TYPE, "typeof_type", 't', 0) This is not an alias, but is later expanded into multiple aliases. */ DEFTREECODE (USING_DECL, "using_decl", 'd', 0) +/* A using directive. The operand is USING_STMT_NAMESPACE. */ +DEFTREECODE (USING_STMT, "using_directive", 'e', 1) + /* An un-parsed default argument. Looks like an IDENTIFIER_NODE. */ DEFTREECODE (DEFAULT_ARG, "default_arg", 'x', 2) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index a8b22a4ea5a..69623fbc335 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -3051,6 +3051,8 @@ extern int flag_new_for_scope; #define EH_SPEC_STMTS(NODE) TREE_OPERAND (EH_SPEC_BLOCK_CHECK (NODE), 0) #define EH_SPEC_RAISES(NODE) TREE_OPERAND (EH_SPEC_BLOCK_CHECK (NODE), 1) +#define USING_STMT_NAMESPACE(NODE) TREE_OPERAND (USING_STMT_CHECK (NODE), 0) + /* Nonzero if this try block is a function try block. */ #define FN_TRY_BLOCK_P(NODE) TREE_LANG_FLAG_3 (TRY_BLOCK_CHECK (NODE)) #define HANDLER_PARMS(NODE) TREE_OPERAND (HANDLER_CHECK (NODE), 0) @@ -3058,7 +3060,6 @@ extern int flag_new_for_scope; #define SUBOBJECT_CLEANUP(NODE) TREE_OPERAND (SUBOBJECT_CHECK (NODE), 0) #define START_CATCH_TYPE(NODE) TREE_TYPE (START_CATCH_STMT_CHECK (NODE)) - /* Nonzero if this CTOR_STMT is for the beginning of a constructor. */ #define CTOR_BEGIN_P(NODE) \ (TREE_LANG_FLAG_0 (CTOR_STMT_CHECK (NODE))) diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 8cfc9da4d2c..bc6a9897467 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -5204,18 +5204,23 @@ do_using_directive (namespace) { if (namespace == fake_std_node) return; + if (building_stmt_tree ()) + add_stmt (build_stmt (USING_STMT, namespace)); + /* using namespace A::B::C; */ if (TREE_CODE (namespace) == SCOPE_REF) namespace = TREE_OPERAND (namespace, 1); if (TREE_CODE (namespace) == IDENTIFIER_NODE) { /* Lookup in lexer did not find a namespace. */ - cp_error ("namespace `%T' undeclared", namespace); + if (!processing_template_decl) + cp_error ("namespace `%T' undeclared", namespace); return; } if (TREE_CODE (namespace) != NAMESPACE_DECL) { - cp_error ("`%T' is not a namespace", namespace); + if (!processing_template_decl) + cp_error ("`%T' is not a namespace", namespace); return; } namespace = ORIGINAL_NAMESPACE (namespace); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 2a1dc4414ae..c0cd2ebc42d 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -6886,7 +6886,7 @@ tsubst_copy (t, args, complain, in_decl) case LOOKUP_EXPR: { - /* We must tsbust into a LOOKUP_EXPR in case the names to + /* We must tsubst into a LOOKUP_EXPR in case the names to which it refers is a conversion operator; in that case the name will change. We avoid making unnecessary copies, however. */ @@ -7211,6 +7211,12 @@ tsubst_expr (t, args, complain, in_decl) args, complain, in_decl)); break; + case USING_STMT: + prep_stmt (t); + do_using_directive (tsubst_expr (USING_STMT_NAMESPACE (t), + args, complain, in_decl)); + break; + case DECL_STMT: { tree decl; diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 5a42fd034a2..8b7e99bef2c 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -2220,6 +2220,9 @@ cp_expand_stmt (t) genrtl_named_return_value (); break; + case USING_STMT: + break; + default: my_friendly_abort (19990810); break; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 12d5b6e4e21..33106b4009d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2001-05-01 Nathan Sidwell + + * g++.old-deja/g++.ns/template17.C: New test. + 2001-05-01 Nathan Sidwell * g++.old-deja/g++.pt/ref4.C: New test. diff --git a/gcc/testsuite/g++.old-deja/g++.ns/template17.C b/gcc/testsuite/g++.old-deja/g++.ns/template17.C new file mode 100644 index 00000000000..11f21c921e1 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.ns/template17.C @@ -0,0 +1,37 @@ +// Build don't link: +// +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 29 Apr 2001 + +// Bug 2258. We failed to implement using directives inside template +// functions. This makes us regress now that ::std is real. + +namespace thing +{ + template T end2 (T); +} +namespace whatever +{ +} + +template void fn (T, T (*)(T)); + +template void mycout(const T& data) +{ + using namespace thing; + using namespace whatever; + + fn (data, end2); + fn (data, end3); +} + +namespace whatever +{ + template T end3 (T); +} + +int main() +{ + double data = 5.0; + mycout(data); +}