Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td	(revision 149797)
+++ include/clang/Basic/DiagnosticSemaKinds.td	(working copy)
@@ -163,7 +163,9 @@
 def warn_return_value_size: Warning<
   "return value of %0 is a large (%1 bytes) pass-by-value object; "
   "pass it by reference instead ?">, InGroup<LargeByValueCopy>;
-
+def warn_return_value_udt: Warning<
+  "%0 has C-linkage specified, but returns UDT %1 which is incompatible "
+  "with C">, InGroup<ReturnType>;
 def warn_implicit_function_decl : Warning<
   "implicit declaration of function %0">,
   InGroup<ImplicitFunctionDeclare>, DefaultIgnore;
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp	(revision 149797)
+++ lib/Sema/SemaDecl.cpp	(working copy)
@@ -5774,6 +5774,17 @@
         Context.BuiltinInfo.ForgetBuiltin(BuiltinID, Context.Idents);
       }
     }
+  
+    // 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()) {
+      QualType R = NewFD->getResultType();
+      if (!R.isPODType(Context) && 
+          !R->isScalarType() && !R->isVoidType())
+        Diag( NewFD->getLocation(), diag::warn_return_value_udt ) 
+          << NewFD << R;
+    }
   }
   return Redeclaration;
 }
Index: test/SemaCXX/function-extern-c.cpp
===================================================================
--- test/SemaCXX/function-extern-c.cpp	(revision 0)
+++ test/SemaCXX/function-extern-c.cpp	(working copy)
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -Wreturn-type -fsyntax-only -std=c++11 -verify %s
+
+class A {
+public:
+  A(const A&);
+};
+
+struct S {
+  int i;
+  double d;
+
+  virtual void B() {}
+};
+
+union U {
+  struct {
+    int i;
+    virtual void B() {} // Can only do this in C++11
+  } t;
+};
+
+struct S2 {
+  int i;
+  double d;
+};
+
+extern "C" U f3( void ); // expected-warning {{'f3' has C-linkage specified, but returns UDT 'U' which is incompatible with C}}
+extern "C" S f0(void); // expected-warning {{'f0' has C-linkage specified, but returns UDT 'S' which is incompatible with C}}
+extern "C" A f4( void ); // expected-warning {{'f4' has C-linkage specified, but returns UDT 'A' which is incompatible with C}}
+
+// These should all be fine
+extern "C" S2 f5( void );
+extern "C" void f2( A x );
+extern "C" void f6( S s );
+extern "C" void f7( U u );
+extern "C" double f8(void);
+extern "C" long long f11( void );
+extern "C" A *f10( void );
\ No newline at end of file
Index: test/SemaCXX/function-extern-c.cpp
===================================================================
--- test/SemaCXX/function-extern-c.cpp	(revision 0)
+++ test/SemaCXX/function-extern-c.cpp	(working copy)

Property changes on: test/SemaCXX/function-extern-c.cpp
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
