Eli Friedman | eca3ed7 | 2011-06-13 23:56:42 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Eli Friedman | 85a5319 | 2009-04-07 19:37:57 +0000 | [diff] [blame] | 2 | |
Jordan Rose | 11b46a0 | 2012-06-18 17:49:58 +0000 | [diff] [blame^] | 3 | #if defined(INCLUDE) |
| 4 | // ------- |
| 5 | // This section acts like a header file. |
| 6 | // ------- |
Jordan Rose | 106af9e | 2012-06-15 18:19:48 +0000 | [diff] [blame] | 7 | |
| 8 | // Check the use of static variables in non-static inline functions. |
Jordan Rose | 11b46a0 | 2012-06-18 17:49:58 +0000 | [diff] [blame^] | 9 | static int staticVar; // expected-note + {{'staticVar' declared here}} |
| 10 | static int staticFunction(); // expected-note + {{'staticFunction' declared here}} |
Jordan Rose | 106af9e | 2012-06-15 18:19:48 +0000 | [diff] [blame] | 11 | |
| 12 | inline int useStatic () { // expected-note 2 {{use 'static' to give inline function 'useStatic' internal linkage}} |
| 13 | staticFunction(); // expected-warning{{function 'staticFunction' has internal linkage but is used in an inline function with external linkage}} |
| 14 | return staticVar; // expected-warning{{variable 'staticVar' has internal linkage but is used in an inline function with external linkage}} |
| 15 | } |
| 16 | |
| 17 | extern inline int useStaticFromExtern () { // no suggestions |
| 18 | staticFunction(); // expected-warning{{function 'staticFunction' has internal linkage but is used in an inline function with external linkage}} |
| 19 | return staticVar; // expected-warning{{variable 'staticVar' has internal linkage but is used in an inline function with external linkage}} |
| 20 | } |
| 21 | |
| 22 | static inline int useStaticFromStatic () { |
| 23 | staticFunction(); // no-warning |
| 24 | return staticVar; // no-warning |
| 25 | } |
Jordan Rose | 11b46a0 | 2012-06-18 17:49:58 +0000 | [diff] [blame^] | 26 | |
| 27 | #else |
| 28 | // ------- |
| 29 | // This is the main source file. |
| 30 | // ------- |
| 31 | |
| 32 | #define INCLUDE |
| 33 | #include "inline.c" |
| 34 | |
| 35 | // Check that we don't allow illegal uses of inline |
| 36 | inline int a; // expected-error{{'inline' can only appear on functions}} |
| 37 | typedef inline int b; // expected-error{{'inline' can only appear on functions}} |
| 38 | int d(inline int a); // expected-error{{'inline' can only appear on functions}} |
| 39 | |
| 40 | // Check that the warnings from the "header file" aren't on by default in |
| 41 | // the main source file. |
| 42 | |
| 43 | inline int useStaticMain () { |
| 44 | staticFunction(); // no-warning |
| 45 | return staticVar; // no-warning |
| 46 | } |
| 47 | |
| 48 | // Check that the warnings show up when explicitly requested. |
| 49 | |
| 50 | #pragma clang diagnostic push |
| 51 | #pragma clang diagnostic warning "-Winternal-linkage-in-inline" |
| 52 | |
| 53 | inline int useStaticAgain () { // expected-note 2 {{use 'static' to give inline function 'useStaticAgain' internal linkage}} |
| 54 | staticFunction(); // expected-warning{{function 'staticFunction' has internal linkage but is used in an inline function with external linkage}} |
| 55 | return staticVar; // expected-warning{{variable 'staticVar' has internal linkage but is used in an inline function with external linkage}} |
| 56 | } |
| 57 | |
| 58 | #pragma clang diagnostic pop |
| 59 | |
| 60 | #endif |
| 61 | |
| 62 | |