98 lines · cpp
1// RUN: %clang_cc1 -Wreturn-type -fsyntax-only -std=c++11 -verify %s2 3class A {4public:5 A(const A&);6};7 8struct S {9 int i;10 double d;11 12 virtual void B() {}13};14 15union U {16 struct {17 int i;18 virtual void B() {} // Can only do this in C++1119 } t;20};21 22struct S2 {23 int i;24 double d;25};26 27extern "C" U f3( void ); // expected-warning {{'f3' has C-linkage specified, but returns user-defined type 'U' which is incompatible with C}}28extern "C" S f0(void); // expected-warning {{'f0' has C-linkage specified, but returns user-defined type 'S' which is incompatible with C}}29extern "C" A f4( void ); // expected-warning {{'f4' has C-linkage specified, but returns user-defined type 'A' which is incompatible with C}}30 31// These should all be fine32extern "C" S2 f5( void );33extern "C" void f2( A x );34extern "C" void f6( S s );35extern "C" void f7( U u );36extern "C" double f8(void);37extern "C" long long f11( void );38extern "C" A *f10( void );39 40extern "C" struct mypodstruct f12(); // expected-warning {{'f12' has C-linkage specified, but returns incomplete type 'struct mypodstruct' which could be incompatible with C}}41 42namespace test2 {43 // FIXME: we should probably suppress the first warning as the second one44 // is more precise.45 // For now this tests that a second 'extern "C"' is not necessary to trigger46 // the warning.47 struct A;48 extern "C" A f(void); // expected-warning {{'f' has C-linkage specified, but returns incomplete type 'A' which could be incompatible with C}}49 struct A {50 A(const A&);51 };52 A f(void); // no warning. warning is already issued on first declaration.53}54 55namespace test3 {56 struct A {57 A(const A&);58 };59 extern "C" {60 // Don't warn for static functions.61 static A f(void);62 }63}64 65namespace rdar13364028 {66class A {67public:68 virtual int x();69};70 71extern "C" {72#pragma clang diagnostic push73#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"74A xyzzy();75#pragma clang diagnostic pop76A bbb(); // expected-warning {{'bbb' has C-linkage specified, but returns user-defined type 'A' which is incompatible with C}}77A ccc() { // expected-warning {{'ccc' has C-linkage specified, but returns user-defined type 'A' which is incompatible with C}}78 return A();79};80}81 82A xyzzy();83 84A xyzzy()85{86 return A();87}88 89A bbb()90{91 return A();92}93 94A bbb();95 96A ccc();97}98