decl2.c (do_nonmember_using_decl): Don't complain if we find same function.
authorNathan Sidwell <nathan@codesourcery.com>
Thu, 1 Mar 2001 13:51:00 +0000 (13:51 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Thu, 1 Mar 2001 13:51:00 +0000 (13:51 +0000)
cp:
* decl2.c (do_nonmember_using_decl): Don't complain if we find
same function. Do complain about ambiguating extern "C"
declarations.
testsuite:
* g++.old-deja/g++.other/using9.C: New test.

From-SVN: r40148

gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.old-deja/g++.other/using9.C [new file with mode: 0644]

index fc3fb94..c5d0c95 100644 (file)
@@ -1,3 +1,9 @@
+2001-03-01  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * decl2.c (do_nonmember_using_decl): Don't complain if we find
+       same function. Do complain about ambiguating extern "C"
+       declarations.
+
 2001-02-28  Nathan Sidwell  <nathan@codesourcery.com>
 
        Remove floating point and complex type template constant parms.
index b371611..d115dcc 100644 (file)
@@ -5126,22 +5126,21 @@ do_nonmember_using_decl (scope, name, oldval, oldtype, newval, newtype)
            {
              tree old_fn = OVL_CURRENT (tmp1);
 
-             if (!OVL_USED (tmp1)
-                 && compparms (TYPE_ARG_TYPES (TREE_TYPE (new_fn)),
-                               TYPE_ARG_TYPES (TREE_TYPE (old_fn))))
+              if (new_fn == old_fn)
+                /* The function already exists in the current namespace.  */
+                break;
+             else if (OVL_USED (tmp1))
+               continue; /* this is a using decl */
+             else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (new_fn)),
+                                 TYPE_ARG_TYPES (TREE_TYPE (old_fn))))
                {
-                 if (!(DECL_EXTERN_C_P (new_fn)
-                       && DECL_EXTERN_C_P (old_fn)))
-                   /* There was already a non-using declaration in
-                      this scope with the same parameter types.  */
-                   cp_error ("`%D' is already declared in this scope",
-                             name);
+                 /* 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))
+                   cp_error ("`%D' is already declared in this scope", name);
                  break;
                }
-             else if (duplicate_decls (new_fn, old_fn))
-               /* We're re-using something we already used 
-                  before.  We don't need to add it again.  */ 
-               break;
            }
 
          /* If we broke out of the loop, there's no reason to add
index fd0371d..414c253 100644 (file)
@@ -1,3 +1,7 @@
+2001-03-01  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * g++.old-deja/g++.other/using9.C: New test.
+
 2001-02-28  Ovidiu Predescu  <ovidiu@cup.hp.com>
 
        * objc/execute/bycopy-3.m: Added new test from Nicola Pero.
diff --git a/gcc/testsuite/g++.old-deja/g++.other/using9.C b/gcc/testsuite/g++.old-deja/g++.other/using9.C
new file mode 100644 (file)
index 0000000..acfab50
--- /dev/null
@@ -0,0 +1,21 @@
+// Build don't link:
+// 
+// Copyright (C) 2000 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 26 Feb 2001 <nathan@codesourcery.com>
+
+// Bug 75. using declarations cannot introduce functions which ambiguate
+// those in the current namespace, BUT here we're reaccessing the current
+// namespace -- the function is not being 'introduced'.
+
+extern int a();
+struct x {};
+
+using ::x;
+using ::a;
+
+extern "C" void foo ();
+
+namespace {
+  extern "C" int foo ();
+  using ::foo; // ERROR - already in use
+}