summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema/inline.c
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-06-18 17:49:58 +0000
committerJordan Rose <jordan_rose@apple.com>2012-06-18 17:49:58 +0000
commitedff0200115c2bdfe44fe77a2d10a22a38808d98 (patch)
tree4977d7c6a3aeadea45b832bf020ed92019d3f474 /clang/test/Sema/inline.c
parent9563a053de1337ec8827cf170e39345d541ef87c (diff)
downloadbcm5719-llvm-edff0200115c2bdfe44fe77a2d10a22a38808d98.tar.gz
bcm5719-llvm-edff0200115c2bdfe44fe77a2d10a22a38808d98.zip
Allow internal decls in inline functions if the function is in the main file.
This handles the very common case of people writing inline functions in their main source files and not tagging them as inline. These cases should still behave as the user intended. (The diagnostic is still emitted as an extension.) I'm reworking this code anyway to account for C++'s equivalent restriction in [basic.def.odr]p6, but this should get some bots back to green. llvm-svn: 158666
Diffstat (limited to 'clang/test/Sema/inline.c')
-rw-r--r--clang/test/Sema/inline.c50
1 files changed, 43 insertions, 7 deletions
diff --git a/clang/test/Sema/inline.c b/clang/test/Sema/inline.c
index 37dba8c3821..23eedd6b226 100644
--- a/clang/test/Sema/inline.c
+++ b/clang/test/Sema/inline.c
@@ -1,14 +1,13 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
-// Check that we don't allow illegal uses of inline
-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}}
-
+#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 2 {{'staticVar' declared here}}
-static int staticFunction(); // expected-note 2 {{'staticFunction' declared here}}
+static int staticVar; // expected-note + {{'staticVar' declared here}}
+static int staticFunction(); // expected-note + {{'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}}
@@ -24,3 +23,40 @@ static inline int useStaticFromStatic () {
staticFunction(); // no-warning
return staticVar; // no-warning
}
+
+#else
+// -------
+// This is the main source file.
+// -------
+
+#define INCLUDE
+#include "inline.c"
+
+// Check that we don't allow illegal uses of inline
+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 that the warnings from the "header file" aren't on by default in
+// the main source file.
+
+inline int useStaticMain () {
+ staticFunction(); // no-warning
+ return staticVar; // no-warning
+}
+
+// Check that the warnings show up when explicitly requested.
+
+#pragma clang diagnostic push
+#pragma clang diagnostic warning "-Winternal-linkage-in-inline"
+
+inline int useStaticAgain () { // expected-note 2 {{use 'static' to give inline function 'useStaticAgain' 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}}
+}
+
+#pragma clang diagnostic pop
+
+#endif
+
+
OpenPOWER on IntegriCloud