Home | History | Annotate | Download | only in Sema
      1 // 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(dllexport) typedef int typedef1; // expected-warning{{'dllexport' attribute only applies to variables and functions}}
      8 typedef __declspec(dllexport) int typedef2; // expected-warning{{'dllexport' attribute only applies to variables and functions}}
      9 typedef int __declspec(dllexport) typedef3; // expected-warning{{'dllexport' attribute only applies to variables and functions}}
     10 typedef __declspec(dllexport) void (*FunTy)(); // expected-warning{{'dllexport' attribute only applies to variables and functions}}
     11 enum __declspec(dllexport) Enum { EnumVal }; // expected-warning{{'dllexport' attribute only applies to variables and functions}}
     12 struct __declspec(dllexport) Record {}; // expected-warning{{'dllexport' attribute only applies to variables and functions}}
     13 
     14 
     15 
     16 //===----------------------------------------------------------------------===//
     17 // Globals
     18 //===----------------------------------------------------------------------===//
     19 
     20 // Export declaration.
     21 __declspec(dllexport) extern int ExternGlobalDecl;
     22 
     23 // dllexport implies a definition.
     24 __declspec(dllexport) int GlobalDef;
     25 
     26 // Export definition.
     27 __declspec(dllexport) int GlobalInit1 = 1;
     28 int __declspec(dllexport) GlobalInit2 = 1;
     29 
     30 // Declare, then export definition.
     31 __declspec(dllexport) extern int GlobalDeclInit;
     32 int GlobalDeclInit = 1;
     33 
     34 // Redeclarations
     35 __declspec(dllexport) extern int GlobalRedecl1;
     36 __declspec(dllexport)        int GlobalRedecl1;
     37 
     38 __declspec(dllexport) extern int GlobalRedecl2;
     39                              int GlobalRedecl2;
     40 
     41                       extern int GlobalRedecl3; // expected-note{{previous declaration is here}}
     42 __declspec(dllexport) extern int GlobalRedecl3; // expected-error{{redeclaration of 'GlobalRedecl3' cannot add 'dllexport' attribute}}
     43 
     44 // External linkage is required.
     45 __declspec(dllexport) static int StaticGlobal; // expected-error{{'StaticGlobal' must have external linkage when declared 'dllexport'}}
     46 
     47 // Export in local scope.
     48 void functionScope() {
     49   __declspec(dllexport)        int LocalVarDecl; // expected-error{{'LocalVarDecl' must have external linkage when declared 'dllexport'}}
     50   __declspec(dllexport)        int LocalVarDef = 1; // expected-error{{'LocalVarDef' must have external linkage when declared 'dllexport'}}
     51   __declspec(dllexport) extern int ExternLocalVarDecl;
     52   __declspec(dllexport) static int StaticLocalVar; // expected-error{{'StaticLocalVar' must have external linkage when declared 'dllexport'}}
     53 }
     54 
     55 
     56 
     57 //===----------------------------------------------------------------------===//
     58 // Functions
     59 //===----------------------------------------------------------------------===//
     60 
     61 // Export function declaration. Check different placements.
     62 __attribute__((dllexport)) void decl1A(); // Sanity check with __attribute__
     63 __declspec(dllexport)      void decl1B();
     64 
     65 void __attribute__((dllexport)) decl2A();
     66 void __declspec(dllexport)      decl2B();
     67 
     68 // Export function definition.
     69 __declspec(dllexport) void def() {}
     70 
     71 // Export inline function.
     72 __declspec(dllexport) inline void inlineFunc1() {}
     73 extern void inlineFunc1();
     74 
     75 inline void __attribute__((dllexport)) inlineFunc2() {}
     76 extern void inlineFunc2();
     77 
     78 // Redeclarations
     79 __declspec(dllexport) void redecl1();
     80 __declspec(dllexport) void redecl1();
     81 
     82 __declspec(dllexport) void redecl2();
     83                       void redecl2();
     84 
     85 __declspec(dllexport) void redecl3();
     86                       void redecl3() {}
     87 
     88                       void redecl4(); // expected-note{{previous declaration is here}}
     89 __declspec(dllexport) void redecl4(); // expected-error{{redeclaration of 'redecl4' cannot add 'dllexport' attribute}}
     90 
     91                       void redecl5(); // expected-note{{previous declaration is here}}
     92 __declspec(dllexport) inline void redecl5() {} // expected-error{{redeclaration of 'redecl5' cannot add 'dllexport' attribute}}
     93 
     94 // External linkage is required.
     95 __declspec(dllexport) static int staticFunc(); // expected-error{{'staticFunc' must have external linkage when declared 'dllexport'}}
     96 
     97 
     98 
     99 //===----------------------------------------------------------------------===//
    100 // Precedence
    101 //===----------------------------------------------------------------------===//
    102 
    103 // dllexport takes precedence over dllimport if both are specified.
    104 __attribute__((dllimport, dllexport))       extern int PrecedenceExternGlobal1A; // expected-warning{{'dllimport' attribute ignored}}
    105 __declspec(dllimport) __declspec(dllexport) extern int PrecedenceExternGlobal1B; // expected-warning{{'dllimport' attribute ignored}}
    106 
    107 __attribute__((dllexport, dllimport))       extern int PrecedenceExternGlobal2A; // expected-warning{{'dllimport' attribute ignored}}
    108 __declspec(dllexport) __declspec(dllimport) extern int PrecedenceExternGlobal2B; // expected-warning{{'dllimport' attribute ignored}}
    109 
    110 __attribute__((dllimport, dllexport))       int PrecedenceGlobal1A; // expected-warning{{'dllimport' attribute ignored}}
    111 __declspec(dllimport) __declspec(dllexport) int PrecedenceGlobal1B; // expected-warning{{'dllimport' attribute ignored}}
    112 
    113 __attribute__((dllexport, dllimport))       int PrecedenceGlobal2A; // expected-warning{{'dllimport' attribute ignored}}
    114 __declspec(dllexport) __declspec(dllimport) int PrecedenceGlobal2B; // expected-warning{{'dllimport' attribute ignored}}
    115 
    116 __declspec(dllexport) extern int PrecedenceExternGlobalRedecl1;
    117 __declspec(dllimport) extern int PrecedenceExternGlobalRedecl1; // expected-warning{{'dllimport' attribute ignored}}
    118 
    119 __declspec(dllimport) extern int PrecedenceExternGlobalRedecl2; // expected-warning{{'dllimport' attribute ignored}}
    120 __declspec(dllexport) extern int PrecedenceExternGlobalRedecl2;
    121 
    122 __declspec(dllexport) extern int PrecedenceGlobalRedecl1;
    123 __declspec(dllimport)        int PrecedenceGlobalRedecl1; // expected-warning{{'dllimport' attribute ignored}}
    124 
    125 __declspec(dllimport) extern int PrecedenceGlobalRedecl2; // expected-warning{{'dllimport' attribute ignored}}
    126 __declspec(dllexport)        int PrecedenceGlobalRedecl2;
    127 
    128 void __attribute__((dllimport, dllexport))       precedence1A() {} // expected-warning{{'dllimport' attribute ignored}}
    129 void __declspec(dllimport) __declspec(dllexport) precedence1B() {} // expected-warning{{'dllimport' attribute ignored}}
    130 
    131 void __attribute__((dllexport, dllimport))       precedence2A() {} // expected-warning{{'dllimport' attribute ignored}}
    132 void __declspec(dllexport) __declspec(dllimport) precedence2B() {} // expected-warning{{'dllimport' attribute ignored}}
    133 
    134 void __declspec(dllimport) precedenceRedecl1(); // expected-warning{{'dllimport' attribute ignored}}
    135 void __declspec(dllexport) precedenceRedecl1() {}
    136 
    137 void __declspec(dllexport) precedenceRedecl2();
    138 void __declspec(dllimport) precedenceRedecl2() {} // expected-warning{{'dllimport' attribute ignored}}
    139