blob: ee1ad882b6a9edbce6f573c20809f5048b685fb5 [file] [log] [blame]
Nico Rieck60478662014-02-22 19:47:30 +00001// RUN: %clang_cc1 -triple i686-win32 -fsyntax-only -verify -std=c99 %s
2// RUN: %clang_cc1 -triple x86_64-win32 -fsyntax-only -verify -std=c11 %s
3// RUN: %clang_cc1 -triple i686-mingw32 -fsyntax-only -verify -std=c11 %s
4// RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -verify -std=c99 %s
5
6// Invalid usage.
7__declspec(dllimport) typedef int typedef1; // expected-warning{{'dllimport' attribute only applies to variables and functions}}
8typedef __declspec(dllimport) int typedef2; // expected-warning{{'dllimport' attribute only applies to variables and functions}}
9typedef int __declspec(dllimport) typedef3; // expected-warning{{'dllimport' attribute only applies to variables and functions}}
10typedef __declspec(dllimport) void (*FunTy)(); // expected-warning{{'dllimport' attribute only applies to variables and functions}}
11enum __declspec(dllimport) Enum { EnumVal }; // expected-warning{{'dllimport' attribute only applies to variables and functions}}
12struct __declspec(dllimport) Record {}; // expected-warning{{'dllimport' attribute only applies to variables and functions}}
13
14
15
16//===----------------------------------------------------------------------===//
17// Globals
18//===----------------------------------------------------------------------===//
19
20// Import declaration.
21__declspec(dllimport) extern int ExternGlobalDecl;
22
23// dllimport implies a declaration. FIXME: This should not warn.
24__declspec(dllimport) int GlobalDecl; // expected-warning{{'dllimport' attribute cannot be specified on a definition}}
25
26// Not allowed on definitions.
27__declspec(dllimport) int GlobalInit1 = 1; // expected-warning{{'dllimport' attribute cannot be specified on a definition}}
28int __declspec(dllimport) GlobalInit2 = 1; // expected-warning{{'dllimport' attribute cannot be specified on a definition}}
29
30// Declare, then reject definition.
31__declspec(dllimport) extern int ExternGlobalDeclInit;
32int ExternGlobalDeclInit = 1; // expected-warning{{'dllimport' attribute cannot be specified on a definition}}
33
34// Redeclarations
35__declspec(dllimport) extern int GlobalRedecl1;
36__declspec(dllimport) extern int GlobalRedecl1;
37
38// Import in local scope.
39void functionScope() {
40 __declspec(dllimport) extern int ExternLocalVarDecl;
41}
42
43
44
45//===----------------------------------------------------------------------===//
46// Functions
47//===----------------------------------------------------------------------===//
48
49// Import function declaration. Check different placements.
50__attribute__((dllimport)) void decl1A(); // Sanity check with __attribute__
51__declspec(dllimport) void decl1B();
52
53void __attribute__((dllimport)) decl2A();
54void __declspec(dllimport) decl2B();
55
56// Not allowed on function definitions.
57__declspec(dllimport) void def() {} // expected-error{{'dllimport' attribute can be applied only to symbol declaration}}
58
59// Import inline function.
60__declspec(dllimport) inline void inlineFunc1() {} // expected-warning{{'dllimport' attribute ignored}}
61inline void __attribute__((dllimport)) inlineFunc2() {} // expected-warning{{'dllimport' attribute ignored}}
62
63// Redeclarations
64__declspec(dllimport) void redecl1();
65__declspec(dllimport) void redecl1();
66
67__declspec(dllimport) void redecl3();
68 void redecl3() {} // expected-warning{{'redecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}