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