]> granicus.if.org Git - clang/commitdiff
Tweak warning text for returning incomplete type from extern "C" functions.
authorHans Wennborg <hans@hanshq.net>
Tue, 24 Jul 2012 17:59:41 +0000 (17:59 +0000)
committerHans Wennborg <hans@hanshq.net>
Tue, 24 Jul 2012 17:59:41 +0000 (17:59 +0000)
A warning was added in r150128 for returning non-C compatible
user-defined types from functions with C linkage.

This makes the text more clear for the case when the type isn't
decidedly non-C compatible, but incomplete.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160681 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/SemaCXX/function-extern-c.cpp

index 5c3f1150c36a3670a417e614739867aed27fbefb..67f43d22c814b21fb62f5c99da687ac0b40e2420 100644 (file)
@@ -192,6 +192,9 @@ def warn_return_value_size: Warning<
 def warn_return_value_udt: Warning<
   "%0 has C-linkage specified, but returns user-defined type %1 which is "
   "incompatible with C">, InGroup<ReturnTypeCLinkage>;
+def warn_return_value_udt_incomplete: Warning<
+  "%0 has C-linkage specified, but returns incomplete type %1 which could be "
+  "incompatible with C">, InGroup<ReturnTypeCLinkage>;
 def warn_implicit_function_decl : Warning<
   "implicit declaration of function %0">,
   InGroup<ImplicitFunctionDeclare>, DefaultIgnore;
index 52aa5b72d19790648e6e4196c35f0bc8dbd20124..12444e555941fa7ddeead7c0c84fde4840d904fd 100644 (file)
@@ -6086,10 +6086,11 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD,
     // compatible, and if it does, warn the user.
     if (NewFD->isExternC()) {
       QualType R = NewFD->getResultType();
-      if (!R.isPODType(Context) && 
-          !R->isVoidType())
-        Diag( NewFD->getLocation(), diag::warn_return_value_udt ) 
-          << NewFD << R;
+      if (R->isIncompleteType() && !R->isVoidType())
+        Diag(NewFD->getLocation(), diag::warn_return_value_udt_incomplete)
+            << NewFD << R;
+      else if (!R.isPODType(Context) && !R->isVoidType())
+        Diag(NewFD->getLocation(), diag::warn_return_value_udt) << NewFD << R;
     }
   }
   return Redeclaration;
index f20cd38a3cb0cce0c997f184854bd4465abaec09..16dbbb26fc66d8346c0ec15dc5c394f9a99dfe5c 100644 (file)
@@ -36,3 +36,5 @@ extern "C" void f7( U u );
 extern "C" double f8(void);
 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}}