]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Don't allow template-id in using-declaration.
authorGabriel Dos Reis <gdr@merlin.codesourcery.com>
Mon, 6 Aug 2001 16:04:08 +0000 (16:04 +0000)
committerGabriel Dos Reis <gdr@gcc.gnu.org>
Mon, 6 Aug 2001 16:04:08 +0000 (16:04 +0000)
cp/
       Don't allow template-id in using-declaration.
       * decl2.c (validate_nonmember_using_decl): Handle template-ids.
       (do_class_using_decl): Likewise.

testsuite/
       * g++.dg/other/using-declaration.C: New test.

From-SVN: r44663

gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/other/using-declaration.C [new file with mode: 0644]

index 2911f991c41eea1f27c5e5c96ea4a21d93424c53..470fd8211884ea488484ea796eb3cb120f90152a 100644 (file)
@@ -1,3 +1,9 @@
+2001-08-05  Gabriel Dos Reis  <gdr@merlin.codesourcery.com>
+
+       Don't allow template-id in using-declaration.
+       * decl2.c (validate_nonmember_using_decl): Handle template-ids.
+       (do_class_using_decl): Likewise.
+
 2001-08-04  Neil Booth  <neil@cat.daikokuya.demon.co.uk>
 
        * cp/spew.c (read_token): No need to pop buffers.
index 666c31b81a32deb09098d84ff24f302210eedb67..d35ab7195d28cbe8bc5e7f651e966c20a4fc157f 100644 (file)
@@ -4913,19 +4913,29 @@ validate_nonmember_using_decl (decl, scope, name)
       *scope = TREE_OPERAND (decl, 0);
       *name = TREE_OPERAND (decl, 1);
 
-      /* [namespace.udecl]
-
-        A using-declaration for a class member shall be a
-        member-declaration.  */
-      if (!processing_template_decl
-          && TREE_CODE (*scope) != NAMESPACE_DECL)
-       {
-         if (TYPE_P (*scope))
-           cp_error ("`%T' is not a namespace", *scope);
-         else
-           cp_error ("`%D' is not a namespace", *scope);
-         return NULL_TREE;
-       }
+      if (!processing_template_decl)
+        {
+          /* [namespace.udecl]
+             A using-declaration for a class member shall be a
+             member-declaration.  */
+          if(TREE_CODE (*scope) != NAMESPACE_DECL)
+            {
+              if (TYPE_P (*scope))
+                cp_error ("`%T' is not a namespace", *scope);
+              else
+                cp_error ("`%D' is not a namespace", *scope);
+              return NULL_TREE;
+            }
+          
+          /* 7.3.3/5
+             A using-declaration shall not name a template-id.  */
+          if (TREE_CODE (*name) == TEMPLATE_ID_EXPR)
+            {
+              *name = TREE_OPERAND (*name, 0);
+              cp_error ("a using-declaration cannot specify a template-id.  Try `using %D'", *name);
+              return NULL_TREE;
+            }
+        }
     }
   else if (TREE_CODE (decl) == IDENTIFIER_NODE
            || TREE_CODE (decl) == TYPE_DECL
@@ -5129,7 +5139,13 @@ do_class_using_decl (decl)
       cp_error ("using-declaration for destructor");
       return NULL_TREE;
     }
-  if (TREE_CODE (name) == TYPE_DECL)
+  else if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
+    {
+      name = TREE_OPERAND (name, 0);
+      cp_error ("a using-declaration cannot specify a template-id.  Try  `using %T::%D'", TREE_OPERAND (decl, 0), name);
+      return NULL_TREE;
+    }
+  if (TREE_CODE (name) == TYPE_DECL || TREE_CODE (name) == TEMPLATE_DECL)
     name = DECL_NAME (name);
 
   my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 980716);
index 9e3c8c89b167977cf926afac02470f1b9306d758..3b5930e8d4d6dba414dd7dac5d56512d4621cc14 100644 (file)
@@ -1,3 +1,7 @@
+2001-08-05  Gabriel Dos Reis  <gdr@merlin.codesourcery.com>
+
+       * g++.dg/other/using-declaration.C: New test.
+
 2001-08-05  Neil Booth  <neil@daikokuya.demon.co.uk>
 
        * gcc.dg/cpp/tr-sign.c: New testcase.
diff --git a/gcc/testsuite/g++.dg/other/using-declaration.C b/gcc/testsuite/g++.dg/other/using-declaration.C
new file mode 100644 (file)
index 0000000..aac3342
--- /dev/null
@@ -0,0 +1,44 @@
+// Copyright (C) 2001 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
+
+// { dg-do compile }
+
+namespace N
+{
+  template<int> void f() {}
+}
+
+using N::f< 0 >;     // { dg-error "using-declaration" "" }
+
+struct  A {
+  template <class T> void f(T);
+  template <class T> struct X { };
+}; 
+
+struct B : A {
+  using A::X;        // OK
+  using A::f;        // OK
+};
+
+struct C : A {
+  using A::f<double>; // { dg-error "using-declaration" "" }
+  using A::X<int>;    // { dg-error "parse error" "" }
+};
+