linkage-spec.cpp revision 7b49202090678f45fa0c0bb5fa560d8a27b0c604
1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar// RUN: %clang_cc1 -fsyntax-only -verify %s
26c6fce03ea12b7b8e812fa1b24cfe5aa8705cecaDouglas Gregorextern "C" {
36c6fce03ea12b7b8e812fa1b24cfe5aa8705cecaDouglas Gregor  extern "C" void f(int);
46c6fce03ea12b7b8e812fa1b24cfe5aa8705cecaDouglas Gregor}
56c6fce03ea12b7b8e812fa1b24cfe5aa8705cecaDouglas Gregor
66c6fce03ea12b7b8e812fa1b24cfe5aa8705cecaDouglas Gregorextern "C++" {
76c6fce03ea12b7b8e812fa1b24cfe5aa8705cecaDouglas Gregor  extern "C++" int& g(int);
86c6fce03ea12b7b8e812fa1b24cfe5aa8705cecaDouglas Gregor  float& g();
96c6fce03ea12b7b8e812fa1b24cfe5aa8705cecaDouglas Gregor}
106c6fce03ea12b7b8e812fa1b24cfe5aa8705cecaDouglas Gregordouble& g(double);
116c6fce03ea12b7b8e812fa1b24cfe5aa8705cecaDouglas Gregor
126c6fce03ea12b7b8e812fa1b24cfe5aa8705cecaDouglas Gregorvoid test(int x, double d) {
136c6fce03ea12b7b8e812fa1b24cfe5aa8705cecaDouglas Gregor  f(x);
146c6fce03ea12b7b8e812fa1b24cfe5aa8705cecaDouglas Gregor  float &f1 = g();
156c6fce03ea12b7b8e812fa1b24cfe5aa8705cecaDouglas Gregor  int& i1 = g(x);
166c6fce03ea12b7b8e812fa1b24cfe5aa8705cecaDouglas Gregor  double& d1 = g(d);
176c6fce03ea12b7b8e812fa1b24cfe5aa8705cecaDouglas Gregor}
1817a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregor
1917a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregorextern "C" int foo;
2017a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregorextern "C" int foo;
2117a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregor
2217a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregorextern "C" const int bar;
2317a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregorextern "C" int const bar;
24425bfdee21d7ce13799bb7f9d74805a2d5775762Anders Carlsson
25425bfdee21d7ce13799bb7f9d74805a2d5775762Anders Carlsson// <rdar://problem/6895431>
26425bfdee21d7ce13799bb7f9d74805a2d5775762Anders Carlssonextern "C" struct bar d;
27425bfdee21d7ce13799bb7f9d74805a2d5775762Anders Carlssonextern struct bar e;
28a24eb4ef63d5860a5a02f7532e56e84283782984Douglas Gregor
29a24eb4ef63d5860a5a02f7532e56e84283782984Douglas Gregorextern "C++" {
30a24eb4ef63d5860a5a02f7532e56e84283782984Douglas Gregor  namespace N0 {
31a24eb4ef63d5860a5a02f7532e56e84283782984Douglas Gregor    struct X0 {
32a24eb4ef63d5860a5a02f7532e56e84283782984Douglas Gregor      int foo(int x) { return x; }
33a24eb4ef63d5860a5a02f7532e56e84283782984Douglas Gregor    };
34a24eb4ef63d5860a5a02f7532e56e84283782984Douglas Gregor  }
354fcfde4d5c8f25e40720972a5543d538a0dcb220Daniel Dunbar}
369770ef0eea1dbebb9cad93b8a564bff789568e62Sebastian Redl
379770ef0eea1dbebb9cad93b8a564bff789568e62Sebastian Redl// PR5430
389770ef0eea1dbebb9cad93b8a564bff789568e62Sebastian Redlnamespace pr5430 {
399770ef0eea1dbebb9cad93b8a564bff789568e62Sebastian Redl  extern "C" void func(void);
409770ef0eea1dbebb9cad93b8a564bff789568e62Sebastian Redl}
419770ef0eea1dbebb9cad93b8a564bff789568e62Sebastian Redlusing namespace pr5430;
429770ef0eea1dbebb9cad93b8a564bff789568e62Sebastian Redlextern "C" void pr5430::func(void) { }
431237259bda343504cc0bd3cfe2198bdeea2b2fdfDouglas Gregor
441237259bda343504cc0bd3cfe2198bdeea2b2fdfDouglas Gregor// PR5404
451237259bda343504cc0bd3cfe2198bdeea2b2fdfDouglas Gregorint f2(char *)
461237259bda343504cc0bd3cfe2198bdeea2b2fdfDouglas Gregor{
471237259bda343504cc0bd3cfe2198bdeea2b2fdfDouglas Gregor        return 0;
481237259bda343504cc0bd3cfe2198bdeea2b2fdfDouglas Gregor}
491237259bda343504cc0bd3cfe2198bdeea2b2fdfDouglas Gregor
501237259bda343504cc0bd3cfe2198bdeea2b2fdfDouglas Gregorextern "C"
511237259bda343504cc0bd3cfe2198bdeea2b2fdfDouglas Gregor{
521237259bda343504cc0bd3cfe2198bdeea2b2fdfDouglas Gregor    int f2(int)
531237259bda343504cc0bd3cfe2198bdeea2b2fdfDouglas Gregor    {
541237259bda343504cc0bd3cfe2198bdeea2b2fdfDouglas Gregor        return f2((char *)0);
551237259bda343504cc0bd3cfe2198bdeea2b2fdfDouglas Gregor    }
561237259bda343504cc0bd3cfe2198bdeea2b2fdfDouglas Gregor}
5735f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara
5835f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara// PR6991
5935f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnaraextern "C" typedef int (*PutcFunc_t)(int);
607b49202090678f45fa0c0bb5fa560d8a27b0c604John McCall
617b49202090678f45fa0c0bb5fa560d8a27b0c604John McCall
627b49202090678f45fa0c0bb5fa560d8a27b0c604John McCall// PR7859
637b49202090678f45fa0c0bb5fa560d8a27b0c604John McCallextern "C" void pr7859_a(int) {} // expected-note {{previous definition}}
647b49202090678f45fa0c0bb5fa560d8a27b0c604John McCallextern "C" void pr7859_a(int) {} // expected-error {{redefinition}}
657b49202090678f45fa0c0bb5fa560d8a27b0c604John McCall
667b49202090678f45fa0c0bb5fa560d8a27b0c604John McCallextern "C" void pr7859_b() {} // expected-note {{previous definition}}
677b49202090678f45fa0c0bb5fa560d8a27b0c604John McCallextern "C" void pr7859_b(int) {} // expected-error {{conflicting}}
687b49202090678f45fa0c0bb5fa560d8a27b0c604John McCall
697b49202090678f45fa0c0bb5fa560d8a27b0c604John McCallextern "C" void pr7859_c(short) {} // expected-note {{previous definition}}
707b49202090678f45fa0c0bb5fa560d8a27b0c604John McCallextern "C" void pr7859_c(int) {} // expected-error {{conflicting}}
71