diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 26f4a487b1d..83fac5a9f0c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2004-12-09 Matt Austern + + 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 * parser.c (cp_parser_member_declaration): Fix comment typo. diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index cfd3890cea7..eb60421cfaa 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -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)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cc4f1ae43fc..3a733f7e82e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2004-12-09 Matt Austern + + 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 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 index 00000000000..8a53fd6a315 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/builtin1.C @@ -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 index 00000000000..c741c0ba98f --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/builtin2.C @@ -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 index 00000000000..3d06dd7534a --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/builtin3.C @@ -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 index 00000000000..7d6c473dc84 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/builtin4.C @@ -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 index 00000000000..2601a12e301 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/builtin5.C @@ -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" } +}