[RISCV] Rename a lambda to have plural nouns to reflect that it contains a loop. NFC
[llvm-project.git] / clang / test / Sema / dllexport.c
blob3f911fb095c0fc68242c945d7f54323ed2a43104
1 // RUN: %clang_cc1 -triple i686-win32 -fsyntax-only -fms-extensions -verify -std=c99 %s
2 // RUN: %clang_cc1 -triple x86_64-win32 -fsyntax-only -fms-extensions -verify -std=c11 %s
3 // RUN: %clang_cc1 -triple i686-mingw32 -fsyntax-only -fms-extensions -verify -std=c11 %s
4 // RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c99 %s
6 // Invalid usage.
7 __declspec(dllexport) typedef int typedef1;
8 // expected-warning@-1{{'dllexport' attribute only applies to functions, variables, classes, and Objective-C interfaces}}
9 typedef __declspec(dllexport) int typedef2;
10 // expected-warning@-1{{'dllexport' attribute only applies to}}
11 typedef int __declspec(dllexport) typedef3;
12 // expected-warning@-1{{'dllexport' attribute only applies to}}
13 typedef __declspec(dllexport) void (*FunTy)(void);
14 // expected-warning@-1{{'dllexport' attribute only applies to}}
15 enum __declspec(dllexport) Enum { EnumVal };
16 // expected-warning@-1{{'dllexport' attribute only applies to}}
17 struct __declspec(dllexport) Record {};
18 // expected-warning@-1{{'dllexport' attribute only applies to}}
22 //===----------------------------------------------------------------------===//
23 // Globals
24 //===----------------------------------------------------------------------===//
26 // Export declaration.
27 __declspec(dllexport) extern int ExternGlobalDecl;
29 // dllexport implies a definition.
30 __declspec(dllexport) int GlobalDef;
32 // Export definition.
33 __declspec(dllexport) int GlobalInit1 = 1;
34 int __declspec(dllexport) GlobalInit2 = 1;
36 // Declare, then export definition.
37 __declspec(dllexport) extern int GlobalDeclInit;
38 int GlobalDeclInit = 1;
40 // Redeclarations
41 __declspec(dllexport) extern int GlobalRedecl1;
42 __declspec(dllexport) int GlobalRedecl1;
44 __declspec(dllexport) extern int GlobalRedecl2;
45 int GlobalRedecl2;
47 extern int GlobalRedecl3; // expected-note{{previous declaration is here}}
48 int useGlobalRedecl3(void) { return GlobalRedecl3; }
49 __declspec(dllexport) extern int GlobalRedecl3; // expected-error{{redeclaration of 'GlobalRedecl3' cannot add 'dllexport' attribute}}
51 extern int GlobalRedecl4; // expected-note{{previous declaration is here}}
52 __declspec(dllexport) extern int GlobalRedecl4; // expected-warning{{redeclaration of 'GlobalRedecl4' should not add 'dllexport' attribute}}
55 // External linkage is required.
56 __declspec(dllexport) static int StaticGlobal; // expected-error{{'StaticGlobal' must have external linkage when declared 'dllexport'}}
58 // Thread local variables are invalid.
59 __declspec(dllexport) __thread int ThreadLocalGlobal; // expected-error{{'ThreadLocalGlobal' cannot be thread local when declared 'dllexport'}}
61 // Export in local scope.
62 void functionScope(void) {
63 __declspec(dllexport) int LocalVarDecl; // expected-error{{'LocalVarDecl' must have external linkage when declared 'dllexport'}}
64 __declspec(dllexport) int LocalVarDef = 1; // expected-error{{'LocalVarDef' must have external linkage when declared 'dllexport'}}
65 __declspec(dllexport) extern int ExternLocalVarDecl;
66 __declspec(dllexport) static int StaticLocalVar; // expected-error{{'StaticLocalVar' must have external linkage when declared 'dllexport'}}
71 //===----------------------------------------------------------------------===//
72 // Functions
73 //===----------------------------------------------------------------------===//
75 // Export function declaration. Check different placements.
76 __attribute__((dllexport)) void decl1A(void); // Basic check with __attribute__
77 __declspec(dllexport) void decl1B(void);
79 void __attribute__((dllexport)) decl2A(void);
80 void __declspec(dllexport) decl2B(void);
82 // Export function definition.
83 __declspec(dllexport) void def(void) {}
85 // Export inline function.
86 __declspec(dllexport) inline void inlineFunc1(void) {}
87 extern void inlineFunc1(void);
89 inline void __attribute__((dllexport)) inlineFunc2(void) {}
90 extern void inlineFunc2(void);
92 // Redeclarations
93 __declspec(dllexport) void redecl1(void);
94 __declspec(dllexport) void redecl1(void);
96 __declspec(dllexport) void redecl2(void);
97 void redecl2(void);
99 __declspec(dllexport) void redecl3(void);
100 void redecl3(void) {}
102 void redecl4(void); // expected-note{{previous declaration is here}}
103 void useRedecl4(void) { redecl4(); }
104 __declspec(dllexport) void redecl4(void); // expected-error{{redeclaration of 'redecl4' cannot add 'dllexport' attribute}}
106 void redecl5(void); // expected-note{{previous declaration is here}}
107 void useRedecl5(void) { redecl5(); }
108 __declspec(dllexport) inline void redecl5(void) {} // expected-error{{redeclaration of 'redecl5' cannot add 'dllexport' attribute}}
110 // Allow with a warning if the decl hasn't been used yet.
111 void redecl6(void); // expected-note{{previous declaration is here}}
112 __declspec(dllexport) void redecl6(void); // expected-warning{{redeclaration of 'redecl6' should not add 'dllexport' attribute}}
115 // External linkage is required.
116 __declspec(dllexport) static int staticFunc(void); // expected-error{{'staticFunc' must have external linkage when declared 'dllexport'}}
118 // Static locals don't count as having external linkage.
119 void staticLocalFunc(void) {
120 __declspec(dllexport) static int staticLocal; // expected-error{{'staticLocal' must have external linkage when declared 'dllexport'}}
125 //===----------------------------------------------------------------------===//
126 // Precedence
127 //===----------------------------------------------------------------------===//
129 // dllexport takes precedence over dllimport if both are specified.
130 __attribute__((dllimport, dllexport)) extern int PrecedenceExternGlobal1A; // expected-warning{{'dllimport' attribute ignored}}
131 __declspec(dllimport) __declspec(dllexport) extern int PrecedenceExternGlobal1B; // expected-warning{{'dllimport' attribute ignored}}
133 __attribute__((dllexport, dllimport)) extern int PrecedenceExternGlobal2A; // expected-warning{{'dllimport' attribute ignored}}
134 __declspec(dllexport) __declspec(dllimport) extern int PrecedenceExternGlobal2B; // expected-warning{{'dllimport' attribute ignored}}
136 __attribute__((dllimport, dllexport)) int PrecedenceGlobal1A; // expected-warning{{'dllimport' attribute ignored}}
137 __declspec(dllimport) __declspec(dllexport) int PrecedenceGlobal1B; // expected-warning{{'dllimport' attribute ignored}}
139 __attribute__((dllexport, dllimport)) int PrecedenceGlobal2A; // expected-warning{{'dllimport' attribute ignored}}
140 __declspec(dllexport) __declspec(dllimport) int PrecedenceGlobal2B; // expected-warning{{'dllimport' attribute ignored}}
142 __declspec(dllexport) extern int PrecedenceExternGlobalRedecl1;
143 __declspec(dllimport) extern int PrecedenceExternGlobalRedecl1; // expected-warning{{'dllimport' attribute ignored}}
145 __declspec(dllimport) extern int PrecedenceExternGlobalRedecl2; // expected-warning{{'dllimport' attribute ignored}}
146 __declspec(dllexport) extern int PrecedenceExternGlobalRedecl2;
148 __declspec(dllexport) extern int PrecedenceGlobalRedecl1;
149 __declspec(dllimport) int PrecedenceGlobalRedecl1; // expected-warning{{'dllimport' attribute ignored}}
151 __declspec(dllimport) extern int PrecedenceGlobalRedecl2; // expected-warning{{'dllimport' attribute ignored}}
152 __declspec(dllexport) int PrecedenceGlobalRedecl2;
154 void __attribute__((dllimport, dllexport)) precedence1A(void) {} // expected-warning{{'dllimport' attribute ignored}}
155 void __declspec(dllimport) __declspec(dllexport) precedence1B(void) {} // expected-warning{{'dllimport' attribute ignored}}
157 void __attribute__((dllexport, dllimport)) precedence2A(void) {} // expected-warning{{'dllimport' attribute ignored}}
158 void __declspec(dllexport) __declspec(dllimport) precedence2B(void) {} // expected-warning{{'dllimport' attribute ignored}}
160 void __declspec(dllimport) precedenceRedecl1(void); // expected-warning{{'dllimport' attribute ignored}}
161 void __declspec(dllexport) precedenceRedecl1(void) {}
163 void __declspec(dllexport) precedenceRedecl2(void);
164 void __declspec(dllimport) precedenceRedecl2(void) {} // expected-warning{{'dllimport' attribute ignored}}