1 // { dg-do compile } 2 3 // Copyright 2005 Free Software Foundation 4 // by Alexandre Oliva <aoliva@redhat.com> 5 // based on https://bugzilla.redhat.com/beta/show_bug.cgi?id=149098 6 7 // Per the ISO C++ 90 Standard, using declarations before of after a 8 // declaration of the same function name and prototype should be 9 // errors (7.3.3/11). However, DR 101's resolution recommends 10 // accepting such duplicates if they denote the same function, which 11 // means extern "C" declarations are supposed to match and be 12 // accepted. 13 14 // This test makes sure we reject or accept regular and using 15 // declarations regardless of order as appropriate, and that having 16 // built-in declarations or overloads doesn't affet the outcome. 17 18 namespace std { 19 extern "C" void exit (int) throw (); // these are built-in (extern "C") 20 extern "C" void *malloc (__SIZE_TYPE__) throw () __attribute__((malloc)); 21 22 void abort (void) throw (); // these aren't 23 void _exit (int) throw (); // { dg-message "std::_exit" } 24 25 extern "C" void c1 (void) throw (); 26 void C1 (void) throw (); // { dg-message "std::C1" } 27 28 extern "C" void c2 (void) throw (); 29 void C2 (void) throw (); 30 31 extern "C" void c3 (void) throw (); 32 void C3 (void) throw (); // { dg-message "std::C3" } 33 } 34 35 namespace other { 36 extern "C" void c3 (void) throw (); 37 void C3 (void) throw (); // { dg-message "other::C3" } 38 } 39 40 using std::exit; 41 using std::_exit; 42 using std::c1; 43 using std::C1; 44 45 extern "C" void exit (int) throw (); 46 extern "C" void *malloc (__SIZE_TYPE__) throw () __attribute__((malloc)); 47 48 void abort (void) throw (); // { dg-message "previous" } 49 void _exit (int) throw (); // { dg-error "conflicts" "conflicts" } 50 // { dg-message "void _exit" "_exit" { target *-*-* } 49 } 51 52 extern "C" void c1 (void) throw (); 53 void C1 (void) throw (); // { dg-error "conflicts" "conflicts" } 54 // { dg-message "void C1" "C1" { target *-*-* } 53 } 55 56 extern "C" void c2 (void) throw (); 57 void C2 (void) throw (); // { dg-message "previous" } 58 59 int C3 (int) throw (); 60 61 using std::malloc; 62 using std::abort; // { dg-error "conflicts" } 63 using std::c2; 64 using std::C2; // { dg-error "conflicts" } 65 66 using std::c3; using other::c3; 67 using std::C3; using other::C3; 68 69 long C3 (long) throw (); 70 main()71int main () { 72 malloc (0); 73 exit (0); 74 75 _exit (0); // { dg-error "ambiguous" } 76 // { dg-message "candidate" "candidate note" { target *-*-* } 75 } 77 abort (); 78 79 c1 (); 80 C1 (); // { dg-error "ambiguous" } 81 // { dg-message "candidate" "candidate note" { target *-*-* } 80 } 82 83 c2 (); 84 C2 (); // one might expect an ambiguous call error here as well, but 85 // we don't add the using decl if we find it to be in error. 86 87 c3 (); 88 C3 (); // { dg-error "ambiguous" } 89 // { dg-message "candidate" "candidate note" { target *-*-* } 88 } 90 C3 (0); 91 C3 (0l); 92 } 93