diff options
| author | Fariborz Jahanian <fjahanian@apple.com> | 2013-03-14 23:09:00 +0000 |
|---|---|---|
| committer | Fariborz Jahanian <fjahanian@apple.com> | 2013-03-14 23:09:00 +0000 |
| commit | 95236b50ce51aff7cd1d3b3a3c5a8475cd93bcb2 (patch) | |
| tree | 6321310d3e983bdccb8ecd4603eb2b486ccdb5c8 /clang | |
| parent | 3e56dd4fc94a189505f80c09422470f81ce19ca4 (diff) | |
| download | bcm5719-llvm-95236b50ce51aff7cd1d3b3a3c5a8475cd93bcb2.tar.gz bcm5719-llvm-95236b50ce51aff7cd1d3b3a3c5a8475cd93bcb2.zip | |
Diagnose about extern "C" functions returning c++ objects
on first declaration only. // rdar://13364028
llvm-svn: 177127
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 3 | ||||
| -rw-r--r-- | clang/test/SemaCXX/function-extern-c.cpp | 37 |
2 files changed, 38 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 4c6da45e5b3..245bc2c0e78 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -6793,7 +6793,8 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, // If this function is declared as being extern "C", then check to see if // the function returns a UDT (class, struct, or union type) that is not C // compatible, and if it does, warn the user. - if (NewFD->isExternC()) { + // But, issue any diagnostic on the first declaration only. + if (NewFD->isExternC() && Previous.empty()) { QualType R = NewFD->getResultType(); if (R->isIncompleteType() && !R->isVoidType()) Diag(NewFD->getLocation(), diag::warn_return_value_udt_incomplete) diff --git a/clang/test/SemaCXX/function-extern-c.cpp b/clang/test/SemaCXX/function-extern-c.cpp index a4b8400abcf..6ab96573506 100644 --- a/clang/test/SemaCXX/function-extern-c.cpp +++ b/clang/test/SemaCXX/function-extern-c.cpp @@ -49,7 +49,7 @@ namespace test2 { struct A { A(const A&); }; - A f(void); // expected-warning {{'f' has C-linkage specified, but returns user-defined type 'test2::A' which is incompatible with C}} + A f(void); // no warning. warning is already issued on first declaration. } namespace test3 { @@ -61,3 +61,38 @@ namespace test3 { static A f(void); } } + +// rdar://13364028 +namespace rdar13364028 { +class A { +public: + virtual int x(); +}; + +extern "C" { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wreturn-type-c-linkage" +A xyzzy(); +#pragma clang diagnostic pop +A bbb(); // expected-warning {{'bbb' has C-linkage specified, but returns user-defined type 'rdar13364028::A' which is incompatible with C}} +A ccc() { // expected-warning {{'ccc' has C-linkage specified, but returns user-defined type 'rdar13364028::A' which is incompatible with C}} + return A(); +}; +} + +A xyzzy(); + +A xyzzy() +{ + return A(); +} + +A bbb() +{ + return A(); +} + +A bbb(); + +A ccc(); +} |

