diff options
author | Jordan Rose <jordan_rose@apple.com> | 2012-06-20 18:50:06 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2012-06-20 18:50:06 +0000 |
commit | de9e9764681a25a7adbea48ccb0be4ee98e1fec5 (patch) | |
tree | cb12752b13dbd1e4773e7b729a933bd3038f379f /clang/test/SemaCXX/inline.cpp | |
parent | 43b7c021b3ec06c71c095475a3e8169f58f5775f (diff) | |
download | bcm5719-llvm-de9e9764681a25a7adbea48ccb0be4ee98e1fec5.tar.gz bcm5719-llvm-de9e9764681a25a7adbea48ccb0be4ee98e1fec5.zip |
Remove -Winternal-linkage-in-inline in C++.
It's very easy for anonymous external linkage to propagate in C++ through
return types and parameter types. Likewise, it's possible that a template
containing an inline function is only used with parameters that have internal
linkage. Actually diagnosing where the internal linkage comes from is fairly
difficult (both to locate and then to print nicely). Finally, since we only
have one translation unit available, we can't even prove that any of this
violates the ODR.
This warning needs better-defined behavior in C++ before it can really go in.
Rewording of the C warning (which /is/ specified by C99) coming shortly.
llvm-svn: 158836
Diffstat (limited to 'clang/test/SemaCXX/inline.cpp')
-rw-r--r-- | clang/test/SemaCXX/inline.cpp | 105 |
1 files changed, 0 insertions, 105 deletions
diff --git a/clang/test/SemaCXX/inline.cpp b/clang/test/SemaCXX/inline.cpp index 6f3570e3ca0..e569300faf7 100644 --- a/clang/test/SemaCXX/inline.cpp +++ b/clang/test/SemaCXX/inline.cpp @@ -1,110 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -#if defined(INCLUDE) -// ------- -// This section acts like a header file. -// ------- - -// Check the use of static variables in non-static inline functions. -static int staticVar; // expected-note + {{'staticVar' declared here}} -static int staticFunction(); // expected-note + {{'staticFunction' declared here}} -const int constVar = 0; // no-warning - -namespace { - int anonVar; // expected-note + {{'anonVar' declared here}} - int anonFunction(); // expected-note + {{'anonFunction' declared here}} - const int anonConstVar = 0; // no-warning - - class Anon { - public: - static int var; // expected-note + {{'var' declared here}} - static const int constVar = 0; // no-warning - }; -} - -inline void useStatic() { // expected-note + {{use 'static' to give inline function 'useStatic' internal linkage}} - staticFunction(); // expected-warning{{function 'staticFunction' has internal linkage but is used in an inline function with external linkage}} - (void)staticVar; // expected-warning{{variable 'staticVar' has internal linkage but is used in an inline function with external linkage}} - anonFunction(); // expected-warning{{function 'anonFunction' is in an anonymous namespace but is used in an inline function with external linkage}} - (void)anonVar; // expected-warning{{variable 'anonVar' is in an anonymous namespace but is used in an inline function with external linkage}} - (void)Anon::var; // expected-warning{{variable 'var' is in an anonymous namespace but is used in an inline function with external linkage}} - - (void)constVar; // no-warning - (void)anonConstVar; // no-warning - (void)Anon::constVar; // no-warning -} - -extern inline int useStaticFromExtern() { // no suggestions - staticFunction(); // expected-warning{{function 'staticFunction' has internal linkage but is used in an inline function with external linkage}} - return staticVar; // expected-warning{{variable 'staticVar' has internal linkage but is used in an inline function with external linkage}} -} - -class A { -public: - static inline int useInClass() { // no suggestions - return staticFunction(); // expected-warning{{function 'staticFunction' has internal linkage but is used in an inline method with external linkage}} - } - inline int useInInstance() { // no suggestions - return staticFunction(); // expected-warning{{function 'staticFunction' has internal linkage but is used in an inline method with external linkage}} - } -}; - -static inline void useStaticFromStatic () { - // No warnings. - staticFunction(); - (void)staticVar; - (void)constVar; - anonFunction(); - (void)anonVar; - (void)anonConstVar; - (void)Anon::var; - (void)Anon::constVar; -} - -namespace { - inline void useStaticFromAnon() { - // No warnings. - staticFunction(); - (void)staticVar; - (void)constVar; - anonFunction(); - (void)anonVar; - (void)anonConstVar; - (void)Anon::var; - (void)Anon::constVar; - } -} - -#else -// ------- -// This is the main source file. -// ------- - -#define INCLUDE -#include "inline.cpp" - // Check that we don't allow illegal uses of inline // (checking C++-only constructs here) struct c {inline int a;}; // expected-error{{'inline' can only appear on functions}} - -// Check that the warnings from the "header file" aren't on by default in -// the main source file. - -inline int useStaticMainFile () { - anonFunction(); // no-warning - return staticVar; // no-warning -} - -// Check that the warnings don't show up even when explicitly requested in C++. - -#pragma clang diagnostic push -#pragma clang diagnostic warning "-Winternal-linkage-in-inline" - -inline int useStaticAgain () { - anonFunction(); // no-warning - return staticVar; // no-warning -} - -#pragma clang diagnostic pop - -#endif |