Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / gcc / testsuite / g++.dg / overload / using2.C
blob514d83f34d8801a63b76961c81ea616f298717f3
1 // { dg-do compile }
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
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.
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.
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));
22   void abort (void) throw (); // these aren't
23   void _exit (int) throw (); // { dg-message "std::_exit" }
25   extern "C" void c1 (void) throw ();
26   void C1 (void) throw (); // { dg-message "std::C1" }
28   extern "C" void c2 (void) throw ();
29   void C2 (void) throw ();
31   extern "C" void c3 (void) throw ();
32   void C3 (void) throw (); // { dg-message "std::C3" }
35 namespace other {
36   extern "C" void c3 (void) throw ();
37   void C3 (void) throw (); // { dg-message "other::C3" }
40 using std::exit;
41 using std::_exit;
42 using std::c1;
43 using std::C1;
45   extern "C" void exit (int) throw ();
46   extern "C" void *malloc (__SIZE_TYPE__) throw () __attribute__((malloc));
48   void abort (void) throw ();
49   void _exit (int) throw (); // { dg-error "conflicts" "conflicts" }
50                              // { dg-message "void _exit" "_exit" { target *-*-* } 49 }
52   extern "C" void c1 (void) throw ();
53   void C1 (void) throw (); // { dg-error "conflicts" "conflicts" }
54                            // { dg-message "void C1" "C1" { target *-*-* } 53 }
56   extern "C" void c2 (void) throw ();
57   void C2 (void) throw ();
59   int C3 (int) throw ();
61 using std::malloc;
62 using std::abort; // { dg-error "already declared" }
63 using std::c2;
64 using std::C2; // { dg-error "already declared" }
66 using std::c3; using other::c3;
67 using std::C3; using other::C3;
69   long C3 (long) throw ();
71 int main () {
72   malloc (0);
73   exit (0);
75   _exit (0); // { dg-error "ambiguous" }
76   // { dg-message "candidate" "candidate note" { target *-*-* } 75 }
77   abort ();
79   c1 ();
80   C1 (); // { dg-error "ambiguous" }
81   // { dg-message "candidate" "candidate note" { target *-*-* } 80 }
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.
87   c3 ();
88   C3 (); // { dg-error "ambiguous" }
89   // { dg-message "candidate" "candidate note" { target *-*-* } 88 }
90   C3 (0);
91   C3 (0l);