]> granicus.if.org Git - clang/commitdiff
Use hasCLanguageLinkage when warning about non C return types.
authorRafael Espindola <rafael.espindola@gmail.com>
Sun, 30 Dec 2012 20:40:41 +0000 (20:40 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Sun, 30 Dec 2012 20:40:41 +0000 (20:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171263 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/function-extern-c.cpp

index c9d0c7750c6c1a3e231ab4505bc4db2f21900335..8d3abe7301040871f92ca96ead8c4cbb0064db74 100644 (file)
@@ -6266,7 +6266,7 @@ 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()) {
+    if (NewFD->hasCLanguageLinkage()) {
       QualType R = NewFD->getResultType();
       if (R->isIncompleteType() && !R->isVoidType())
         Diag(NewFD->getLocation(), diag::warn_return_value_udt_incomplete)
index 16dbbb26fc66d8346c0ec15dc5c394f9a99dfe5c..2a073c79fc40bc553d9c56fb91c7214a40eeb02b 100644 (file)
@@ -38,3 +38,16 @@ extern "C" long long f11( void );
 extern "C" A *f10( void );
 
 extern "C" struct mypodstruct f12(); // expected-warning {{'f12' has C-linkage specified, but returns incomplete type 'struct mypodstruct' which could be incompatible with C}}
+
+namespace test2 {
+  // FIXME: we should probably suppress the first warning as the second one
+  // is more precise.
+  // For now this tests that a second 'extern "C"' is not necessary to trigger
+  // the warning.
+  struct A;
+  extern "C" A f(void); // expected-warning {{'f' has C-linkage specified, but returns incomplete type 'test2::A' which could be incompatible with C}}
+  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}}
+}