r177127 - Diagnose about extern "C" functions returning c++ objects

Fariborz Jahanian fjahanian at apple.com
Thu Mar 14 16:09:01 PDT 2013


Author: fjahanian
Date: Thu Mar 14 18:09:00 2013
New Revision: 177127

URL: http://llvm.org/viewvc/llvm-project?rev=177127&view=rev
Log:
Diagnose about extern "C" functions returning c++ objects
on first declaration only. // rdar://13364028

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/function-extern-c.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=177127&r1=177126&r2=177127&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Mar 14 18:09:00 2013
@@ -6793,7 +6793,8 @@ bool Sema::CheckFunctionDeclaration(Scop
     // 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)

Modified: cfe/trunk/test/SemaCXX/function-extern-c.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/function-extern-c.cpp?rev=177127&r1=177126&r2=177127&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/function-extern-c.cpp (original)
+++ cfe/trunk/test/SemaCXX/function-extern-c.cpp Thu Mar 14 18:09:00 2013
@@ -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();
+}





More information about the cfe-commits mailing list