OSDN Git Service

PR c++/19395
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 31 Jan 2005 04:07:41 +0000 (04:07 +0000)
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 31 Jan 2005 04:07:41 +0000 (04:07 +0000)
* decl.c (grokdeclarator): Refactor code so that qualified names
are never allowed as the declarator in a typedef.

PR c++/19367
* name-lookup.c (do_nonmember_using_decl): Avoid overloading
builtin declarations.

PR c++/19395
* g++.dg/parse/error24.C: New test.

PR c++/19367
* g++.dg/lookup/builtin1.C: New test.

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

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/name-lookup.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/lookup/builtin1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/parse/error24.C [new file with mode: 0644]

index 1902735..0b1f7d1 100644 (file)
@@ -1,5 +1,13 @@
 2005-01-30  Mark Mitchell  <mark@codesourcery.com>
 
+       PR c++/19395
+       * decl.c (grokdeclarator): Refactor code so that qualified names
+       are never allowed as the declarator in a typedef.
+
+       PR c++/19367
+       * name-lookup.c (do_nonmember_using_decl): Avoid overloading
+       builtin declarations.
+
        PR c++/19457
        * call.c (convert_like_real): Inline call to
        dubious_conversion_warnings here.
index f65427a..e2408e3 100644 (file)
@@ -7524,18 +7524,14 @@ grokdeclarator (const cp_declarator *declarator,
        TYPE_FOR_JAVA (type) = 1;
 
       if (decl_context == FIELD)
-       {
-         if (constructor_name_p (unqualified_id, current_class_type))
-           pedwarn ("ISO C++ forbids nested type %qD with same name "
-                     "as enclosing class",
-                    unqualified_id);
-         decl = build_lang_decl (TYPE_DECL, unqualified_id, type);
-       }
+       decl = build_lang_decl (TYPE_DECL, unqualified_id, type);
       else
+       decl = build_decl (TYPE_DECL, unqualified_id, type);
+      if (id_declarator && declarator->u.id.qualifying_scope)
+       error ("%Jtypedef name may not be a nested-name-specifier", decl);
+
+      if (decl_context != FIELD)
        {
-         decl = build_decl (TYPE_DECL, unqualified_id, type);
-         if (in_namespace || ctype)
-           error ("%Jtypedef name may not be a nested-name-specifier", decl);
          if (!current_function_decl)
            DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
          else if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (current_function_decl)
@@ -7547,6 +7543,10 @@ grokdeclarator (const cp_declarator *declarator,
               clones.  */
            DECL_ABSTRACT (decl) = 1;
        }
+      else if (constructor_name_p (unqualified_id, current_class_type))
+       pedwarn ("ISO C++ forbids nested type %qD with same name "
+                "as enclosing class",
+                unqualified_id);
 
       /* If the user declares "typedef struct {...} foo" then the
         struct will have an anonymous name.  Fill that name in now.
index bb40e53..b72ded0 100644 (file)
@@ -2036,6 +2036,15 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype,
          oldval = NULL_TREE;
        }
 
+      /* It is impossible to overload a built-in function; any
+        explicit declaration eliminates the built-in declaration.
+        So, if OLDVAL is a built-in, then we can just pretend it
+        isn't there.  */
+      if (oldval 
+         && TREE_CODE (oldval) == FUNCTION_DECL
+         && DECL_ANTICIPATED (oldval))
+       oldval = NULL_TREE;
+
       *newval = oldval;
       for (tmp = decls.value; tmp; tmp = OVL_NEXT (tmp))
        {
@@ -2059,33 +2068,18 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype,
              else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (new_fn)),
                                  TYPE_ARG_TYPES (TREE_TYPE (old_fn))))
                {
+                 gcc_assert (!DECL_ANTICIPATED (old_fn));
+
                  /* There was already a non-using declaration in
                     this scope with the same parameter types. If both
                     are the same extern "C" functions, that's ok.  */
                   if (decls_match (new_fn, old_fn))
-                   {
-                     /* If the OLD_FN was a builtin, we've seen a real 
-                        declaration in another namespace.  Use it instead.
-                        Set tmp1 to NULL so we can use the existing
-                        OVERLOAD logic at the end of this inner loop.
-                     */
-                     if (DECL_ANTICIPATED (old_fn))
-                       {
-                         gcc_assert (! DECL_ANTICIPATED (new_fn));
-                         tmp1 = NULL;
-                       }
-                     break;
-                   }
-                 else if (!DECL_ANTICIPATED (old_fn))
-                   {
-                     /* If the OLD_FN was really declared, the
-                        declarations don't match.  */
+                   break;
+                 else
+                   {
                      error ("%qD is already declared in this scope", name);
                      break;
                    }
-
-                 /* If the OLD_FN was not really there, just ignore
-                    it and keep going.  */
                }
            }
 
index c90f671..0d7f530 100644 (file)
@@ -1,5 +1,11 @@
 2005-01-30  Mark Mitchell  <mark@codesourcery.com>
 
+       PR c++/19395
+       * g++.dg/parse/error24.C: New test. 
+
+       PR c++/19367
+       * g++.dg/lookup/builtin1.C: New test.
+
        PR c++/19457
        * g++.dg/warn/conv3.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/lookup/builtin1.C b/gcc/testsuite/g++.dg/lookup/builtin1.C
new file mode 100644 (file)
index 0000000..5f25f28
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/19367
+// { dg-do link } 
+
+void abort (void) { throw 3; }
+
+namespace std { using ::abort; }
+
+int main ()
+{
+  using std::abort;
+  abort();
+}
diff --git a/gcc/testsuite/g++.dg/parse/error24.C b/gcc/testsuite/g++.dg/parse/error24.C
new file mode 100644 (file)
index 0000000..c072250
--- /dev/null
@@ -0,0 +1,7 @@
+// PR c++/19395
+
+struct A {
+  typedef int ::X; // { dg-error "" }
+};
+
+