summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema/inline.c
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-06-15 18:19:48 +0000
committerJordan Rose <jordan_rose@apple.com>2012-06-15 18:19:48 +0000
commit2684c68ddc2f19c34ab0ed280c1d3238a1279e73 (patch)
tree97659e79c2053deee9f94ecf475759809bc04c00 /clang/test/Sema/inline.c
parent7c0abc34f9efa3caecffa91763aea5eaa8f2a2fd (diff)
downloadbcm5719-llvm-2684c68ddc2f19c34ab0ed280c1d3238a1279e73.tar.gz
bcm5719-llvm-2684c68ddc2f19c34ab0ed280c1d3238a1279e73.zip
Warn when a static variable is referenced in a non-static inline function.
This is explicitly forbidden in C99 6.7.4p3. This is /not/ forbidden in C++, probably because by default file-scope const/constexpr variables have internal linkage, while functions have external linkage. There's also the issue of anonymous namespaces to consider. Nevertheless, there should probably be a similar warning, since the semantics of inlining a function that references a variable with internal linkage do not seem well-defined. <rdar://problem/11577619> llvm-svn: 158531
Diffstat (limited to 'clang/test/Sema/inline.c')
-rw-r--r--clang/test/Sema/inline.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/clang/test/Sema/inline.c b/clang/test/Sema/inline.c
index 3c99f243378..37dba8c3821 100644
--- a/clang/test/Sema/inline.c
+++ b/clang/test/Sema/inline.c
@@ -4,3 +4,23 @@
inline int a; // expected-error{{'inline' can only appear on functions}}
typedef inline int b; // expected-error{{'inline' can only appear on functions}}
int d(inline int a); // expected-error{{'inline' can only appear on functions}}
+
+
+// Check the use of static variables in non-static inline functions.
+static int staticVar; // expected-note 2 {{'staticVar' declared here}}
+static int staticFunction(); // expected-note 2 {{'staticFunction' declared here}}
+
+inline int useStatic () { // expected-note 2 {{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}}
+ return staticVar; // expected-warning{{variable 'staticVar' has internal linkage but is used in an inline function with external linkage}}
+}
+
+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}}
+}
+
+static inline int useStaticFromStatic () {
+ staticFunction(); // no-warning
+ return staticVar; // no-warning
+}
OpenPOWER on IntegriCloud