[cfe-commits] r150128 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/SemaCXX/function-extern-c.cpp
Matt Beaumont-Gay
matthewbg at google.com
Wed Feb 8 18:12:31 PST 2012
Hi Aaron,
The documentation for the corresponding MSVC warning states:
"This is legal if:
* All calls to this function occur from C++.
* The definition of the function is in C++."
For code which triggers the new warning, but is legal per those
criteria, how does one silence the warning?
Thanks,
Matt
On Wed, Feb 8, 2012 at 17:21, Aaron Ballman <aaron at aaronballman.com> wrote:
> Author: aaronballman
> Date: Wed Feb 8 19:21:34 2012
> New Revision: 150128
>
> URL: http://llvm.org/viewvc/llvm-project?rev=150128&view=rev
> Log:
> Adding support for warning when a non-C compatible user-defined type is returned from an extern "C" function.
>
> Fixes bug 6143
>
> Added:
> cfe/trunk/test/SemaCXX/function-extern-c.cpp (with props)
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaDecl.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=150128&r1=150127&r2=150128&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Feb 8 19:21:34 2012
> @@ -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 user-defined type %1 which is "
> + "incompatible with C">, InGroup<ReturnType>;
> def warn_implicit_function_decl : Warning<
> "implicit declaration of function %0">,
> InGroup<ImplicitFunctionDeclare>, DefaultIgnore;
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=150128&r1=150127&r2=150128&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Feb 8 19:21:34 2012
> @@ -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->isVoidType())
> + Diag( NewFD->getLocation(), diag::warn_return_value_udt )
> + << NewFD << R;
> + }
> }
> return Redeclaration;
> }
>
> Added: cfe/trunk/test/SemaCXX/function-extern-c.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/function-extern-c.cpp?rev=150128&view=auto
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/function-extern-c.cpp (added)
> +++ cfe/trunk/test/SemaCXX/function-extern-c.cpp Wed Feb 8 19:21:34 2012
> @@ -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 user-defined type 'U' which is incompatible with C}}
> +extern "C" S f0(void); // expected-warning {{'f0' has C-linkage specified, but returns user-defined type 'S' which is incompatible with C}}
> +extern "C" A f4( void ); // expected-warning {{'f4' has C-linkage specified, but returns user-defined type '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 );
>
> Propchange: cfe/trunk/test/SemaCXX/function-extern-c.cpp
> ------------------------------------------------------------------------------
> svn:eol-style = native
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list