Commit 9da99f7d by Nathan Sidwell Committed by Nathan Sidwell

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
parent 6496a589
2001-05-01 Nathan Sidwell <nathan@codesourcery.com> 2001-05-01 Nathan Sidwell <nathan@codesourcery.com>
* 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 <nathan@codesourcery.com>
* call.c (build_new_op): Convert args from reference here. * call.c (build_new_op): Convert args from reference here.
(build_conditional_expr): Don't convert here. (build_conditional_expr): Don't convert here.
......
...@@ -171,6 +171,9 @@ DEFTREECODE (TYPEOF_TYPE, "typeof_type", 't', 0) ...@@ -171,6 +171,9 @@ DEFTREECODE (TYPEOF_TYPE, "typeof_type", 't', 0)
This is not an alias, but is later expanded into multiple aliases. */ This is not an alias, but is later expanded into multiple aliases. */
DEFTREECODE (USING_DECL, "using_decl", 'd', 0) 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. */ /* An un-parsed default argument. Looks like an IDENTIFIER_NODE. */
DEFTREECODE (DEFAULT_ARG, "default_arg", 'x', 2) DEFTREECODE (DEFAULT_ARG, "default_arg", 'x', 2)
......
...@@ -3051,6 +3051,8 @@ extern int flag_new_for_scope; ...@@ -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_STMTS(NODE) TREE_OPERAND (EH_SPEC_BLOCK_CHECK (NODE), 0)
#define EH_SPEC_RAISES(NODE) TREE_OPERAND (EH_SPEC_BLOCK_CHECK (NODE), 1) #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. */ /* 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 FN_TRY_BLOCK_P(NODE) TREE_LANG_FLAG_3 (TRY_BLOCK_CHECK (NODE))
#define HANDLER_PARMS(NODE) TREE_OPERAND (HANDLER_CHECK (NODE), 0) #define HANDLER_PARMS(NODE) TREE_OPERAND (HANDLER_CHECK (NODE), 0)
...@@ -3058,7 +3060,6 @@ extern int flag_new_for_scope; ...@@ -3058,7 +3060,6 @@ extern int flag_new_for_scope;
#define SUBOBJECT_CLEANUP(NODE) TREE_OPERAND (SUBOBJECT_CHECK (NODE), 0) #define SUBOBJECT_CLEANUP(NODE) TREE_OPERAND (SUBOBJECT_CHECK (NODE), 0)
#define START_CATCH_TYPE(NODE) TREE_TYPE (START_CATCH_STMT_CHECK (NODE)) #define START_CATCH_TYPE(NODE) TREE_TYPE (START_CATCH_STMT_CHECK (NODE))
/* Nonzero if this CTOR_STMT is for the beginning of a constructor. */ /* Nonzero if this CTOR_STMT is for the beginning of a constructor. */
#define CTOR_BEGIN_P(NODE) \ #define CTOR_BEGIN_P(NODE) \
(TREE_LANG_FLAG_0 (CTOR_STMT_CHECK (NODE))) (TREE_LANG_FLAG_0 (CTOR_STMT_CHECK (NODE)))
......
...@@ -5204,18 +5204,23 @@ do_using_directive (namespace) ...@@ -5204,18 +5204,23 @@ do_using_directive (namespace)
{ {
if (namespace == fake_std_node) if (namespace == fake_std_node)
return; return;
if (building_stmt_tree ())
add_stmt (build_stmt (USING_STMT, namespace));
/* using namespace A::B::C; */ /* using namespace A::B::C; */
if (TREE_CODE (namespace) == SCOPE_REF) if (TREE_CODE (namespace) == SCOPE_REF)
namespace = TREE_OPERAND (namespace, 1); namespace = TREE_OPERAND (namespace, 1);
if (TREE_CODE (namespace) == IDENTIFIER_NODE) if (TREE_CODE (namespace) == IDENTIFIER_NODE)
{ {
/* Lookup in lexer did not find a namespace. */ /* 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; return;
} }
if (TREE_CODE (namespace) != NAMESPACE_DECL) 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; return;
} }
namespace = ORIGINAL_NAMESPACE (namespace); namespace = ORIGINAL_NAMESPACE (namespace);
......
...@@ -6886,7 +6886,7 @@ tsubst_copy (t, args, complain, in_decl) ...@@ -6886,7 +6886,7 @@ tsubst_copy (t, args, complain, in_decl)
case LOOKUP_EXPR: 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 which it refers is a conversion operator; in that case the
name will change. We avoid making unnecessary copies, name will change. We avoid making unnecessary copies,
however. */ however. */
...@@ -7211,6 +7211,12 @@ tsubst_expr (t, args, complain, in_decl) ...@@ -7211,6 +7211,12 @@ tsubst_expr (t, args, complain, in_decl)
args, complain, in_decl)); args, complain, in_decl));
break; break;
case USING_STMT:
prep_stmt (t);
do_using_directive (tsubst_expr (USING_STMT_NAMESPACE (t),
args, complain, in_decl));
break;
case DECL_STMT: case DECL_STMT:
{ {
tree decl; tree decl;
......
...@@ -2220,6 +2220,9 @@ cp_expand_stmt (t) ...@@ -2220,6 +2220,9 @@ cp_expand_stmt (t)
genrtl_named_return_value (); genrtl_named_return_value ();
break; break;
case USING_STMT:
break;
default: default:
my_friendly_abort (19990810); my_friendly_abort (19990810);
break; break;
......
2001-05-01 Nathan Sidwell <nathan@codesourcery.com> 2001-05-01 Nathan Sidwell <nathan@codesourcery.com>
* g++.old-deja/g++.ns/template17.C: New test.
2001-05-01 Nathan Sidwell <nathan@codesourcery.com>
* g++.old-deja/g++.pt/ref4.C: New test. * g++.old-deja/g++.pt/ref4.C: New test.
2001-04-30 Richard Henderson <rth@redhat.com> 2001-04-30 Richard Henderson <rth@redhat.com>
......
// Build don't link:
//
// Copyright (C) 2001 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 29 Apr 2001 <nathan@codesourcery.com>
// Bug 2258. We failed to implement using directives inside template
// functions. This makes us regress now that ::std is real.
namespace thing
{
template <typename T> T end2 (T);
}
namespace whatever
{
}
template <typename T> void fn (T, T (*)(T));
template <class T> void mycout(const T& data)
{
using namespace thing;
using namespace whatever;
fn (data, end2);
fn (data, end3);
}
namespace whatever
{
template <typename T> T end3 (T);
}
int main()
{
double data = 5.0;
mycout(data);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment