OSDN Git Service

cp:
authornathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 1 May 2001 12:56:12 +0000 (12:56 +0000)
committernathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 1 May 2001 12:56:12 +0000 (12:56 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@41724 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/cp-tree.def
gcc/cp/cp-tree.h
gcc/cp/decl2.c
gcc/cp/pt.c
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.old-deja/g++.ns/template17.C [new file with mode: 0644]

index b082ce2..c3b8cf0 100644 (file)
@@ -1,5 +1,14 @@
 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.
        (build_conditional_expr): Don't convert here.
 
index 486667c..ee104f5 100644 (file)
@@ -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)
 
index a8b22a4..69623fb 100644 (file)
@@ -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)))
index 8cfc9da..bc6a989 100644 (file)
@@ -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);
index 2a1dc44..c0cd2eb 100644 (file)
@@ -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;
index 5a42fd0..8b7e99b 100644 (file)
@@ -2220,6 +2220,9 @@ cp_expand_stmt (t)
       genrtl_named_return_value ();
       break;
 
+    case USING_STMT:
+      break;
+    
     default:
       my_friendly_abort (19990810);
       break;
index 12d5b6e..33106b4 100644 (file)
@@ -1,5 +1,9 @@
 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.
 
 2001-04-30  Richard Henderson  <rth@redhat.com>
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 (file)
index 0000000..11f21c9
--- /dev/null
@@ -0,0 +1,37 @@
+// 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);
+}