Diagnose about extern "C" functions returning c++ objects
on first declaration only. // rdar://13364028
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177127 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 4c6da45..245bc2c 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -6793,7 +6793,8 @@
// 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/test/SemaCXX/function-extern-c.cpp b/test/SemaCXX/function-extern-c.cpp
index a4b8400..6ab9657 100644
--- a/test/SemaCXX/function-extern-c.cpp
+++ b/test/SemaCXX/function-extern-c.cpp
@@ -49,7 +49,7 @@
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 @@
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();
+}