OSDN Git Service

PR c++/18514
authoraustern <austern@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 9 Dec 2004 21:07:01 +0000 (21:07 +0000)
committeraustern <austern@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 9 Dec 2004 21:07:01 +0000 (21:07 +0000)
  * name-lookup.c (do_nonmember_using_decl): A real function
  declaration takes precedence over an anticipated declaration.
  * g++.dg/ext/builtin1.C: New
  * g++.dg/ext/builtin2.C: New
  * g++.dg/ext/builtin3.C: New
  * g++.dg/ext/builtin4.C: New
  * g++.dg/ext/builtin5.C: New

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

gcc/cp/ChangeLog
gcc/cp/name-lookup.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/builtin1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/builtin2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/builtin3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/builtin4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/builtin5.C [new file with mode: 0644]

index 26f4a48..83fac5a 100644 (file)
@@ -1,3 +1,9 @@
+2004-12-09  Matt Austern  <austern@apple.com>
+
+       PR c++/18514
+       * name-lookup.c (do_nonmember_using_decl): A real function
+       declaration takes precedence over an anticipated declaration.
+       
 2004-12-09  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
 
        * parser.c (cp_parser_member_declaration): Fix comment typo.
index cfd3890..eb60421 100644 (file)
@@ -2064,10 +2064,16 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype,
                     are the same extern "C" functions, that's ok.  */
                   if (decls_match (new_fn, old_fn))
                    {
-                     /* If the OLD_FN was a builtin, there is now a
-                        real declaration.  */
+                     /* 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))
-                       DECL_ANTICIPATED (old_fn) = 0;
+                       {
+                         gcc_assert (! DECL_ANTICIPATED (new_fn));
+                         tmp1 = NULL;
+                       }
                      break;
                    }
                  else if (!DECL_ANTICIPATED (old_fn))
index cc4f1ae..3a733f7 100644 (file)
@@ -1,3 +1,12 @@
+2004-12-09  Matt Austern  <austern@apple.com>
+
+       PR c++/18514
+       * g++.dg/ext/builtin1.C: New
+       * g++.dg/ext/builtin2.C: New
+       * g++.dg/ext/builtin3.C: New
+       * g++.dg/ext/builtin4.C: New
+       * g++.dg/ext/builtin5.C: New
+
 2004-12-09  Andrew Pinski  <pinskia@physics.uc.edu>
 
        PR tree-opt/18904
diff --git a/gcc/testsuite/g++.dg/ext/builtin1.C b/gcc/testsuite/g++.dg/ext/builtin1.C
new file mode 100644 (file)
index 0000000..8a53fd6
--- /dev/null
@@ -0,0 +1,10 @@
+// Test whether alternate 'asm' name is applied correctly to
+// builtin in global namespace
+
+// { dg-do compile }
+// { dg-options "" }
+// { dg-final { scan-assembler "fancy_printf" } }
+
+extern "C" int printf(char*, ...) __asm("_fancy_printf");
+
+void foo() { printf("abc"); }
diff --git a/gcc/testsuite/g++.dg/ext/builtin2.C b/gcc/testsuite/g++.dg/ext/builtin2.C
new file mode 100644 (file)
index 0000000..c741c0b
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/18514
+// Test whether alternate 'asm' name is applied correctly to
+// builtin imported into namespace std.
+
+// { dg-do compile }
+// { dg-options "" }
+// { dg-final { scan-assembler "fancy_printf" } }
+
+extern "C" int printf(char*, ...) __asm("_fancy_printf");
+
+namespace std { using ::printf; }
+
+namespace std { void foo() { printf("abc"); } }
diff --git a/gcc/testsuite/g++.dg/ext/builtin3.C b/gcc/testsuite/g++.dg/ext/builtin3.C
new file mode 100644 (file)
index 0000000..3d06dd7
--- /dev/null
@@ -0,0 +1,13 @@
+// Verify that declaring builtin in namespace std doesn't give us
+// declaration in global namespace
+
+// { dg-do compile }
+// { dg-options "" }
+
+namespace std {
+extern "C" int printf(char*, ...);
+}
+
+void foo() {
+  printf("abc");               // { dg-error "not declared" }
+}
diff --git a/gcc/testsuite/g++.dg/ext/builtin4.C b/gcc/testsuite/g++.dg/ext/builtin4.C
new file mode 100644 (file)
index 0000000..7d6c473
--- /dev/null
@@ -0,0 +1,10 @@
+// Verify that builtin is used when declared in global namespace
+
+// { dg-do compile }
+// { dg-options "-Wall" }
+
+extern "C" int printf(const char*,...);
+
+void foo() {
+  printf("%d");                // { dg-warning "too few arguments" }
+}
diff --git a/gcc/testsuite/g++.dg/ext/builtin5.C b/gcc/testsuite/g++.dg/ext/builtin5.C
new file mode 100644 (file)
index 0000000..2601a12
--- /dev/null
@@ -0,0 +1,12 @@
+// Verify that builtin is used when declared in namespace std
+
+// { dg-do compile }
+// { dg-options "-Wall" }
+
+namespace std {
+  extern "C" int printf(const char*,...);
+}
+
+void foo() {
+  std::printf("%d");           // { dg-warning "too few arguments" }
+}