blob: 6c95a7a14b4c14ebb3f435b71bc0dfdf932a81e1 [file] [log] [blame]
Eli Friedmaneca3ed72011-06-13 23:56:42 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Eli Friedman85a53192009-04-07 19:37:57 +00002
Jordan Rose11b46a02012-06-18 17:49:58 +00003#if defined(INCLUDE)
4// -------
5// This section acts like a header file.
6// -------
Jordan Rose106af9e2012-06-15 18:19:48 +00007
8// Check the use of static variables in non-static inline functions.
Jordan Rose11b46a02012-06-18 17:49:58 +00009static int staticVar; // expected-note + {{'staticVar' declared here}}
10static int staticFunction(); // expected-note + {{'staticFunction' declared here}}
Jordan Rose07c877d2012-06-20 21:09:10 +000011static struct { int x; } staticStruct; // expected-note + {{'staticStruct' declared here}}
Jordan Rose106af9e2012-06-15 18:19:48 +000012
Jordan Rose07c877d2012-06-20 21:09:10 +000013inline int useStatic () { // expected-note 3 {{use 'static' to give inline function 'useStatic' internal linkage}}
14 staticFunction(); // expected-warning{{static function 'staticFunction' is used in an inline function with external linkage}}
15 (void)staticStruct.x; // expected-warning{{static variable 'staticStruct' is used in an inline function with external linkage}}
16 return staticVar; // expected-warning{{static variable 'staticVar' is used in an inline function with external linkage}}
Jordan Rose106af9e2012-06-15 18:19:48 +000017}
18
19extern inline int useStaticFromExtern () { // no suggestions
Jordan Rose07c877d2012-06-20 21:09:10 +000020 staticFunction(); // expected-warning{{static function 'staticFunction' is used in an inline function with external linkage}}
21 return staticVar; // expected-warning{{static variable 'staticVar' is used in an inline function with external linkage}}
Jordan Rose106af9e2012-06-15 18:19:48 +000022}
23
24static inline int useStaticFromStatic () {
25 staticFunction(); // no-warning
26 return staticVar; // no-warning
27}
Jordan Rose11b46a02012-06-18 17:49:58 +000028
29#else
30// -------
31// This is the main source file.
32// -------
33
34#define INCLUDE
35#include "inline.c"
36
37// Check that we don't allow illegal uses of inline
38inline int a; // expected-error{{'inline' can only appear on functions}}
39typedef inline int b; // expected-error{{'inline' can only appear on functions}}
40int d(inline int a); // expected-error{{'inline' can only appear on functions}}
41
42// Check that the warnings from the "header file" aren't on by default in
43// the main source file.
44
Jordan Rose0eb3f452012-06-18 22:09:19 +000045inline int useStaticMainFile () {
Jordan Rose11b46a02012-06-18 17:49:58 +000046 staticFunction(); // no-warning
47 return staticVar; // no-warning
48}
49
50// Check that the warnings show up when explicitly requested.
51
52#pragma clang diagnostic push
Jordan Rose07c877d2012-06-20 21:09:10 +000053#pragma clang diagnostic warning "-Wstatic-in-inline"
Jordan Rose11b46a02012-06-18 17:49:58 +000054
55inline int useStaticAgain () { // expected-note 2 {{use 'static' to give inline function 'useStaticAgain' internal linkage}}
Jordan Rose07c877d2012-06-20 21:09:10 +000056 staticFunction(); // expected-warning{{static function 'staticFunction' is used in an inline function with external linkage}}
57 return staticVar; // expected-warning{{static variable 'staticVar' is used in an inline function with external linkage}}
Jordan Rose11b46a02012-06-18 17:49:58 +000058}
59
60#pragma clang diagnostic pop
61
62#endif
63
64