1ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// RUN: %clang_cc1 -triple i686-win32 -fsyntax-only -verify -std=c++11 -DMS %s 2ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// RUN: %clang_cc1 -triple x86_64-win32 -fsyntax-only -verify -std=c++1y -DMS %s 3651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// RUN: %clang_cc1 -triple i686-mingw32 -fsyntax-only -verify -std=c++1y %s 4651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -verify -std=c++11 %s 5651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 6651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// Helper structs to make templates more expressive. 7651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesstruct ImplicitInst_Imported {}; 8651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesstruct ExplicitDecl_Imported {}; 9651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesstruct ExplicitInst_Imported {}; 10651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesstruct ExplicitSpec_Imported {}; 11651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesstruct ExplicitSpec_Def_Imported {}; 12651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesstruct ExplicitSpec_InlineDef_Imported {}; 13651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesstruct ExplicitSpec_NotImported {}; 14651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesnamespace { struct Internal {}; } 15651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 16651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 17651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// Invalid usage. 18ef8225444452a1486bd721f3285301fe84643b00Stephen Hines__declspec(dllimport) typedef int typedef1; // expected-warning{{'dllimport' attribute only applies to variables, functions and classes}} 19ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestypedef __declspec(dllimport) int typedef2; // expected-warning{{'dllimport' attribute only applies to variables, functions and classes}} 20ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestypedef int __declspec(dllimport) typedef3; // expected-warning{{'dllimport' attribute only applies to variables, functions and classes}} 21ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestypedef __declspec(dllimport) void (*FunTy)(); // expected-warning{{'dllimport' attribute only applies to variables, functions and classes}} 22ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesenum __declspec(dllimport) Enum {}; // expected-warning{{'dllimport' attribute only applies to variables, functions and classes}} 23651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#if __has_feature(cxx_strong_enums) 24ef8225444452a1486bd721f3285301fe84643b00Stephen Hines enum class __declspec(dllimport) EnumClass {}; // expected-warning{{'dllimport' attribute only applies to variables, functions and classes}} 25651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#endif 26651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 27651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 28651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 29651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines//===----------------------------------------------------------------------===// 30651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// Globals 31651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines//===----------------------------------------------------------------------===// 32651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 33651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// Import declaration. 34651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) extern int ExternGlobalDecl; 35651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 36651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// dllimport implies a declaration. 37651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) int GlobalDecl; 38651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesint **__attribute__((dllimport))* GlobalDeclChunkAttr; 39651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesint GlobalDeclAttr __attribute__((dllimport)); 40651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 41651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// Not allowed on definitions. 42651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) extern int ExternGlobalInit = 1; // expected-error{{definition of dllimport data}} 43651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) int GlobalInit1 = 1; // expected-error{{definition of dllimport data}} 44651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesint __declspec(dllimport) GlobalInit2 = 1; // expected-error{{definition of dllimport data}} 45651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 46651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// Declare, then reject definition. 47651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) extern int ExternGlobalDeclInit; // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 48651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesint ExternGlobalDeclInit = 1; // expected-warning{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 49651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 50651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) int GlobalDeclInit; // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 51651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesint GlobalDeclInit = 1; // expected-warning{{'GlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 52651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 53651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesint *__attribute__((dllimport)) GlobalDeclChunkAttrInit; // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 54651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesint *GlobalDeclChunkAttrInit = 0; // expected-warning{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 55651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 56651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesint GlobalDeclAttrInit __attribute__((dllimport)); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 57651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesint GlobalDeclAttrInit = 1; // expected-warning{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 58651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 59651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// Redeclarations 60651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) extern int GlobalRedecl1; 61651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) extern int GlobalRedecl1; 62651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 63651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) int GlobalRedecl2a; 64651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) int GlobalRedecl2a; 65651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 66651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesint *__attribute__((dllimport)) GlobalRedecl2b; 67651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesint *__attribute__((dllimport)) GlobalRedecl2b; 68651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 69651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesint GlobalRedecl2c __attribute__((dllimport)); 70651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesint GlobalRedecl2c __attribute__((dllimport)); 71651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 72651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// NB: MSVC issues a warning and makes GlobalRedecl3 dllexport. We follow GCC 73651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// and drop the dllimport with a warning. 74651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) extern int GlobalRedecl3; // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 75651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines extern int GlobalRedecl3; // expected-warning{{'GlobalRedecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 76651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 77651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines extern int GlobalRedecl4; // expected-note{{previous declaration is here}} 78651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) extern int GlobalRedecl4; // expected-error{{redeclaration of 'GlobalRedecl4' cannot add 'dllimport' attribute}} 79651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 80651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// External linkage is required. 81651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) static int StaticGlobal; // expected-error{{'StaticGlobal' must have external linkage when declared 'dllimport'}} 82651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) Internal InternalTypeGlobal; // expected-error{{'InternalTypeGlobal' must have external linkage when declared 'dllimport'}} 83651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesnamespace { __declspec(dllimport) int InternalGlobal; } // expected-error{{'(anonymous namespace)::InternalGlobal' must have external linkage when declared 'dllimport'}} 84651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesnamespace ns { __declspec(dllimport) int ExternalGlobal; } 85651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 86651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) auto InternalAutoTypeGlobal = Internal(); // expected-error{{'InternalAutoTypeGlobal' must have external linkage when declared 'dllimport'}} 87651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines // expected-error@-1{{definition of dllimport data}} 88651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 89651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// Import in local scope. 90651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) float LocalRedecl1; // expected-note{{previous definition is here}} 91651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) float LocalRedecl2; // expected-note{{previous definition is here}} 92651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) float LocalRedecl3; // expected-note{{previous definition is here}} 93651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesvoid functionScope() { 94651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines __declspec(dllimport) int LocalRedecl1; // expected-error{{redefinition of 'LocalRedecl1' with a different type: 'int' vs 'float'}} 95651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines int *__attribute__((dllimport)) LocalRedecl2; // expected-error{{redefinition of 'LocalRedecl2' with a different type: 'int *' vs 'float'}} 96651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines int LocalRedecl3 __attribute__((dllimport)); // expected-error{{redefinition of 'LocalRedecl3' with a different type: 'int' vs 'float'}} 97651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 98651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines __declspec(dllimport) int LocalVarDecl; 99651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines __declspec(dllimport) int LocalVarDef = 1; // expected-error{{definition of dllimport data}} 100651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines __declspec(dllimport) extern int ExternLocalVarDecl; 101651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines __declspec(dllimport) extern int ExternLocalVarDef = 1; // expected-error{{definition of dllimport data}} 102651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines __declspec(dllimport) static int StaticLocalVar; // expected-error{{'StaticLocalVar' must have external linkage when declared 'dllimport'}} 103651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines} 104651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 105651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 106651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 107651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines//===----------------------------------------------------------------------===// 1086bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Variable templates 1096bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines//===----------------------------------------------------------------------===// 1106bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines#if __has_feature(cxx_variable_templates) 1116bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1126bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import declaration. 1136bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) extern int ExternVarTmplDecl; 1146bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1156bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// dllimport implies a declaration. 1166bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) int VarTmplDecl; 1176bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1186bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Not allowed on definitions. 1196bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) extern int ExternVarTmplInit = 1; // expected-error{{definition of dllimport data}} 1206bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) int VarTmplInit1 = 1; // expected-error{{definition of dllimport data}} 1216bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> int __declspec(dllimport) VarTmplInit2 = 1; // expected-error{{definition of dllimport data}} 1226bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1236bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Declare, then reject definition. 1246bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) extern int ExternVarTmplDeclInit; // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 1256bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> int ExternVarTmplDeclInit = 1; // expected-warning{{'ExternVarTmplDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 1266bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1276bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) int VarTmplDeclInit; // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 1286bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> int VarTmplDeclInit = 1; // expected-warning{{'VarTmplDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 1296bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1306bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Redeclarations 1316bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) extern int VarTmplRedecl1; 1326bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) extern int VarTmplRedecl1; 1336bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) int VarTmplRedecl2; 1356bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) int VarTmplRedecl2; 1366bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1376bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) extern int VarTmplRedecl3; // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 1386bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> extern int VarTmplRedecl3; // expected-warning{{'VarTmplRedecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 1396bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1406bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> extern int VarTmplRedecl4; // expected-note{{previous declaration is here}} 1416bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) extern int VarTmplRedecl4; // expected-error{{redeclaration of 'VarTmplRedecl4' cannot add 'dllimport' attribute}} 1426bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1436bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// External linkage is required. 1446bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) static int StaticVarTmpl; // expected-error{{'StaticVarTmpl' must have external linkage when declared 'dllimport'}} 1456bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) Internal InternalTypeVarTmpl; // expected-error{{'InternalTypeVarTmpl' must have external linkage when declared 'dllimport'}} 1466bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesnamespace { template<typename T> __declspec(dllimport) int InternalVarTmpl; } // expected-error{{'(anonymous namespace)::InternalVarTmpl' must have external linkage when declared 'dllimport'}} 1476bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesnamespace ns { template<typename T> __declspec(dllimport) int ExternalVarTmpl; } 1486bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1496bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) auto InternalAutoTypeVarTmpl = Internal(); // expected-error{{definition of dllimport data}} // expected-error{{'InternalAutoTypeVarTmpl' must have external linkage when declared 'dllimport'}} 1506bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1516bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1526bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> int VarTmpl; 1536bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) int ImportedVarTmpl; 1546bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1556bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import implicit instantiation of an imported variable template. 1566bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesint useVarTmpl() { return ImportedVarTmpl<ImplicitInst_Imported>; } 1576bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1586bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import explicit instantiation declaration of an imported variable template. 1596bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesextern template int ImportedVarTmpl<ExplicitDecl_Imported>; 1606bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1616bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// An explicit instantiation definition of an imported variable template cannot 1626bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// be imported because the template must be defined which is illegal. 1636bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1646bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import specialization of an imported variable template. 1656bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<> __declspec(dllimport) int ImportedVarTmpl<ExplicitSpec_Imported>; 1666bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<> __declspec(dllimport) int ImportedVarTmpl<ExplicitSpec_Def_Imported> = 1; // expected-error{{definition of dllimport data}} 1676bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1686bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Not importing specialization of an imported variable template without 1696bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// explicit dllimport. 1706bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<> int ImportedVarTmpl<ExplicitSpec_NotImported>; 1716bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1726bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1736bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import explicit instantiation declaration of a non-imported variable template. 1746bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesextern template __declspec(dllimport) int VarTmpl<ExplicitDecl_Imported>; 1756bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1766bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import explicit instantiation definition of a non-imported variable template. 1776bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate __declspec(dllimport) int VarTmpl<ExplicitInst_Imported>; 1786bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1796bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import specialization of a non-imported variable template. 1806bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<> __declspec(dllimport) int VarTmpl<ExplicitSpec_Imported>; 1816bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<> __declspec(dllimport) int VarTmpl<ExplicitSpec_Def_Imported> = 1; // expected-error{{definition of dllimport data}} 1826bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1836bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines#endif // __has_feature(cxx_variable_templates) 1846bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1856bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1866bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1876bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines//===----------------------------------------------------------------------===// 188651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// Functions 189651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines//===----------------------------------------------------------------------===// 190651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 191651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// Import function declaration. Check different placements. 192651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__attribute__((dllimport)) void decl1A(); // Sanity check with __attribute__ 193651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) void decl1B(); 194651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 195651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesvoid __attribute__((dllimport)) decl2A(); 196651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesvoid __declspec(dllimport) decl2B(); 197651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 198651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// Not allowed on function definitions. 1996bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) void def() {} // expected-error{{dllimport cannot be applied to non-inline function definition}} 200651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 201651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// extern "C" 2026bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesextern "C" __declspec(dllimport) void externC(); 203651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 204651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// Import inline function. 2056bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) inline void inlineFunc1() {} 2066bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesinline void __attribute__((dllimport)) inlineFunc2() {} 2076bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 2086bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) inline void inlineDecl(); 2096bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void inlineDecl() {} 2106bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 2116bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) void inlineDef(); 2126bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines inline void inlineDef() {} 213651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 214651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// Redeclarations 215651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) void redecl1(); 216651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) void redecl1(); 217651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 218651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// NB: MSVC issues a warning and makes redecl2/redecl3 dllexport. We follow GCC 219651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// and drop the dllimport with a warning. 220651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) void redecl2(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 221651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void redecl2(); // expected-warning{{'redecl2' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 222651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 223651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) void redecl3(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 224651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void redecl3() {} // expected-warning{{'redecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 225651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 226651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void redecl4(); // expected-note{{previous declaration is here}} 227651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) void redecl4(); // expected-error{{redeclaration of 'redecl4' cannot add 'dllimport' attribute}} 228651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 2296bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void redecl5(); // expected-note{{previous declaration is here}} 2306bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) inline void redecl5() {} // expected-error{{redeclaration of 'redecl5' cannot add 'dllimport' attribute}} 2316bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 232651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// Friend functions 233651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesstruct FuncFriend { 234651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines friend __declspec(dllimport) void friend1(); 235651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines friend __declspec(dllimport) void friend2(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 236651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines friend __declspec(dllimport) void friend3(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 237651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines friend void friend4(); // expected-note{{previous declaration is here}} 2386bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines friend void friend5(); // expected-note{{previous declaration is here}} 239651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines}; 240651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) void friend1(); 241651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void friend2(); // expected-warning{{'friend2' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 242651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void friend3() {} // expected-warning{{'friend3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 243651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) void friend4(); // expected-error{{redeclaration of 'friend4' cannot add 'dllimport' attribute}} 2446bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) inline void friend5() {} // expected-error{{redeclaration of 'friend5' cannot add 'dllimport' attribute}} 245651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 246651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// Implicit declarations can be redeclared with dllimport. 247651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) void* operator new(__SIZE_TYPE__ n); 248651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 249651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// External linkage is required. 250651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) static int staticFunc(); // expected-error{{'staticFunc' must have external linkage when declared 'dllimport'}} 251651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines__declspec(dllimport) Internal internalRetFunc(); // expected-error{{'internalRetFunc' must have external linkage when declared 'dllimport'}} 252651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesnamespace { __declspec(dllimport) void internalFunc(); } // expected-error{{'(anonymous namespace)::internalFunc' must have external linkage when declared 'dllimport'}} 253651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesnamespace ns { __declspec(dllimport) void externalFunc(); } 254651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 255ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// Import deleted functions. 256ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// FIXME: Deleted functions are definitions so a missing inline is diagnosed 257ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// here which is irrelevant. But because the delete keyword is parsed later 258ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// there is currently no straight-forward way to avoid this diagnostic. 259ef8225444452a1486bd721f3285301fe84643b00Stephen Hines__declspec(dllimport) void deletedFunc() = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}} expected-error{{dllimport cannot be applied to non-inline function definition}} 260ef8225444452a1486bd721f3285301fe84643b00Stephen Hines__declspec(dllimport) inline void deletedInlineFunc() = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}} 261ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 262651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 263651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 264651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines//===----------------------------------------------------------------------===// 265651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// Function templates 266651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines//===----------------------------------------------------------------------===// 267651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 268651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// Import function template declaration. Check different placements. 269651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestemplate<typename T> __declspec(dllimport) void funcTmplDecl1(); 270651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestemplate<typename T> void __declspec(dllimport) funcTmplDecl2(); 271651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 2726bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import function template definition. 2736bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) void funcTmplDef() {} // expected-error{{dllimport cannot be applied to non-inline function definition}} 2746bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 2756bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import inline function template. 2766bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) inline void inlineFuncTmpl1() {} 2776bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> inline void __attribute__((dllimport)) inlineFuncTmpl2() {} 2786bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 2796bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) inline void inlineFuncTmplDecl(); 2806bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> void inlineFuncTmplDecl() {} 2816bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 2826bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) void inlineFuncTmplDef(); 2836bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> inline void inlineFuncTmplDef() {} 2846bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 285651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// Redeclarations 286651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestemplate<typename T> __declspec(dllimport) void funcTmplRedecl1(); 287651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestemplate<typename T> __declspec(dllimport) void funcTmplRedecl1(); 288651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 289651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestemplate<typename T> __declspec(dllimport) void funcTmplRedecl2(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 290651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestemplate<typename T> void funcTmplRedecl2(); // expected-warning{{'funcTmplRedecl2' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 291651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 292651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestemplate<typename T> __declspec(dllimport) void funcTmplRedecl3(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 293651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestemplate<typename T> void funcTmplRedecl3() {} // expected-warning{{'funcTmplRedecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 294651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 295651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestemplate<typename T> void funcTmplRedecl4(); // expected-note{{previous declaration is here}} 296651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestemplate<typename T> __declspec(dllimport) void funcTmplRedecl4(); // expected-error{{redeclaration of 'funcTmplRedecl4' cannot add 'dllimport' attribute}} 297651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 2986bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> void funcTmplRedecl5(); // expected-note{{previous declaration is here}} 2996bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) inline void funcTmplRedecl5() {} // expected-error{{redeclaration of 'funcTmplRedecl5' cannot add 'dllimport' attribute}} 3006bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 301651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// Function template friends 302651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesstruct FuncTmplFriend { 303651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines template<typename T> friend __declspec(dllimport) void funcTmplFriend1(); 304651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines template<typename T> friend __declspec(dllimport) void funcTmplFriend2(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 305651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines template<typename T> friend __declspec(dllimport) void funcTmplFriend3(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 306651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines template<typename T> friend void funcTmplFriend4(); // expected-note{{previous declaration is here}} 3076bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename T> friend __declspec(dllimport) inline void funcTmplFriend5(); 308651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines}; 309651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestemplate<typename T> __declspec(dllimport) void funcTmplFriend1(); 310651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestemplate<typename T> void funcTmplFriend2(); // expected-warning{{'funcTmplFriend2' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 311651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestemplate<typename T> void funcTmplFriend3() {} // expected-warning{{'funcTmplFriend3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 312651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestemplate<typename T> __declspec(dllimport) void funcTmplFriend4(); // expected-error{{redeclaration of 'funcTmplFriend4' cannot add 'dllimport' attribute}} 3136bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> inline void funcTmplFriend5() {} 314651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 315651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// External linkage is required. 316651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestemplate<typename T> __declspec(dllimport) static int staticFuncTmpl(); // expected-error{{'staticFuncTmpl' must have external linkage when declared 'dllimport'}} 317651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestemplate<typename T> __declspec(dllimport) Internal internalRetFuncTmpl(); // expected-error{{'internalRetFuncTmpl' must have external linkage when declared 'dllimport'}} 318651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesnamespace { template<typename T> __declspec(dllimport) void internalFuncTmpl(); } // expected-error{{'(anonymous namespace)::internalFuncTmpl' must have external linkage when declared 'dllimport'}} 319651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesnamespace ns { template<typename T> __declspec(dllimport) void externalFuncTmpl(); } 320651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 321651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 322651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestemplate<typename T> void funcTmpl() {} 3236bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> inline void inlineFuncTmpl() {} 3246bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) void importedFuncTmplDecl(); 3256bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) inline void importedFuncTmpl() {} 3266bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 3276bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import implicit instantiation of an imported function template. 3286bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesvoid useFunTmplDecl() { importedFuncTmplDecl<ImplicitInst_Imported>(); } 3296bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesvoid useFunTmplDef() { importedFuncTmpl<ImplicitInst_Imported>(); } 3306bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 3316bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import explicit instantiation declaration of an imported function template. 3326bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesextern template void importedFuncTmpl<ExplicitDecl_Imported>(); 3336bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 3346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import explicit instantiation definition of an imported function template. 3356bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// NB: MSVC fails this instantiation without explicit dllimport which is most 3366bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// likely a bug because an implicit instantiation is accepted. 3376bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate void importedFuncTmpl<ExplicitInst_Imported>(); 338651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 339651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// Import specialization of an imported function template. A definition must be 340651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// declared inline. 341651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestemplate<> __declspec(dllimport) void importedFuncTmpl<ExplicitSpec_Imported>(); 3426bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<> __declspec(dllimport) void importedFuncTmpl<ExplicitSpec_Def_Imported>() {} // expected-error{{dllimport cannot be applied to non-inline function definition}} 3436bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<> __declspec(dllimport) inline void importedFuncTmpl<ExplicitSpec_InlineDef_Imported>() {} 344651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 345651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// Not importing specialization of an imported function template without 346651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// explicit dllimport. 347651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestemplate<> void importedFuncTmpl<ExplicitSpec_NotImported>() {} 348651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 349651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 350651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// Import explicit instantiation declaration of a non-imported function template. 351651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesextern template __declspec(dllimport) void funcTmpl<ExplicitDecl_Imported>(); 3526bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesextern template __declspec(dllimport) void inlineFuncTmpl<ExplicitDecl_Imported>(); 3536bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 3546bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import explicit instantiation definition of a non-imported function template. 3556bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate __declspec(dllimport) void funcTmpl<ExplicitInst_Imported>(); 3566bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate __declspec(dllimport) void inlineFuncTmpl<ExplicitInst_Imported>(); 357651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 358651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// Import specialization of a non-imported function template. A definition must 359651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// be declared inline. 360651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestemplate<> __declspec(dllimport) void funcTmpl<ExplicitSpec_Imported>(); 3616bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<> __declspec(dllimport) void funcTmpl<ExplicitSpec_Def_Imported>() {} // expected-error{{dllimport cannot be applied to non-inline function definition}} 3626bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<> __declspec(dllimport) inline void funcTmpl<ExplicitSpec_InlineDef_Imported>() {} 3636bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 3646bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 3656bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines//===----------------------------------------------------------------------===// 3666bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Class members 3676bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines//===----------------------------------------------------------------------===// 3686bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 3696bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import individual members of a class. 3706bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesstruct ImportMembers { 3716bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines struct Nested { 3726bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) void normalDecl(); 3736bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) void normalDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 3746bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines }; 3756bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 3766bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) void normalDecl(); 3776bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) void normalDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 3786bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) void normalInclass() {} 3796bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) void normalInlineDef(); 3806bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) inline void normalInlineDecl(); 3816bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) virtual void virtualDecl(); 3826bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) virtual void virtualDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 3836bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) virtual void virtualInclass() {} 3846bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) virtual void virtualInlineDef(); 3856bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) virtual inline void virtualInlineDecl(); 3866bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) static void staticDecl(); 3876bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) static void staticDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 3886bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) static void staticInclass() {} 3896bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) static void staticInlineDef(); 3906bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) static inline void staticInlineDecl(); 3916bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 3926bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesprotected: 3936bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) void protectedDecl(); 3946bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesprivate: 3956bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) void privateDecl(); 396ef8225444452a1486bd721f3285301fe84643b00Stephen Hinespublic: 397ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 398ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) int Field; // expected-warning{{'dllimport' attribute only applies to variables, functions and classes}} 399ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) static int StaticField; 400ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) static int StaticFieldDef; // expected-note{{attribute is here}} 401ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) static const int StaticConstField; 402ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) static const int StaticConstFieldDef; // expected-note{{attribute is here}} 403ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) static const int StaticConstFieldEqualInit = 1; 404ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) static const int StaticConstFieldBraceInit{1}; 405ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) constexpr static int ConstexprField = 1; 406ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) constexpr static int ConstexprFieldDef = 1; // expected-note{{attribute is here}} 4076bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines}; 4086bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 4096bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void ImportMembers::Nested::normalDef() {} // expected-warning{{'ImportMembers::Nested::normalDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 4106bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void ImportMembers::normalDef() {} // expected-warning{{'ImportMembers::normalDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 4116bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesinline void ImportMembers::normalInlineDef() {} 4126bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void ImportMembers::normalInlineDecl() {} 4136bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void ImportMembers::virtualDef() {} // expected-warning{{'ImportMembers::virtualDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 4146bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesinline void ImportMembers::virtualInlineDef() {} 4156bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void ImportMembers::virtualInlineDecl() {} 4166bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void ImportMembers::staticDef() {} // expected-warning{{'ImportMembers::staticDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 4176bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesinline void ImportMembers::staticInlineDef() {} 4186bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void ImportMembers::staticInlineDecl() {} 4196bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 420ef8225444452a1486bd721f3285301fe84643b00Stephen Hines int ImportMembers::StaticFieldDef; // expected-error{{definition of dllimport static field not allowed}} 421ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesconst int ImportMembers::StaticConstFieldDef = 1; // expected-error{{definition of dllimport static field not allowed}} 422ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesconstexpr int ImportMembers::ConstexprFieldDef; // expected-error{{definition of dllimport static field not allowed}} 423ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 4246bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 4256bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import on member definitions. 4266bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesstruct ImportMemberDefs { 4276bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) void normalDef(); 4286bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) void normalInlineDef(); 4296bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) inline void normalInlineDecl(); 4306bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) virtual void virtualDef(); 4316bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) virtual void virtualInlineDef(); 4326bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) virtual inline void virtualInlineDecl(); 4336bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) static void staticDef(); 4346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) static void staticInlineDef(); 4356bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) static inline void staticInlineDecl(); 436ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 437ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) static int StaticField; 438ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) static const int StaticConstField; 439ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) constexpr static int ConstexprField = 1; 4406bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines}; 4416bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 4426bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) void ImportMemberDefs::normalDef() {} // expected-error{{dllimport cannot be applied to non-inline function definition}} 4436bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) inline void ImportMemberDefs::normalInlineDef() {} 4446bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) void ImportMemberDefs::normalInlineDecl() {} 4456bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) void ImportMemberDefs::virtualDef() {} // expected-error{{dllimport cannot be applied to non-inline function definition}} 4466bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) inline void ImportMemberDefs::virtualInlineDef() {} 4476bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) void ImportMemberDefs::virtualInlineDecl() {} 4486bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) void ImportMemberDefs::staticDef() {} // expected-error{{dllimport cannot be applied to non-inline function definition}} 4496bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) inline void ImportMemberDefs::staticInlineDef() {} 4506bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) void ImportMemberDefs::staticInlineDecl() {} 4516bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 452ef8225444452a1486bd721f3285301fe84643b00Stephen Hines__declspec(dllimport) int ImportMemberDefs::StaticField; // expected-error{{definition of dllimport static field not allowed}} expected-note{{attribute is here}} 453ef8225444452a1486bd721f3285301fe84643b00Stephen Hines__declspec(dllimport) const int ImportMemberDefs::StaticConstField = 1; // expected-error{{definition of dllimport static field not allowed}} expected-note{{attribute is here}} 454ef8225444452a1486bd721f3285301fe84643b00Stephen Hines__declspec(dllimport) constexpr int ImportMemberDefs::ConstexprField; // expected-error{{definition of dllimport static field not allowed}} expected-note{{attribute is here}} 455ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 4566bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 4576bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import special member functions. 4586bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesstruct ImportSpecials { 4596bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) ImportSpecials(); 4606bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) ~ImportSpecials(); 4616bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) ImportSpecials(const ImportSpecials&); 4626bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) ImportSpecials& operator=(const ImportSpecials&); 4636bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) ImportSpecials(ImportSpecials&&); 4646bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) ImportSpecials& operator=(ImportSpecials&&); 4656bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines}; 4666bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 4676bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 468ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// Import deleted member functions. 469ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesstruct ImportDeleted { 470ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) ImportDeleted() = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}} 471ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) ~ImportDeleted() = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}} 472ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) ImportDeleted(const ImportDeleted&) = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}} 473ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) ImportDeleted& operator=(const ImportDeleted&) = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}} 474ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) ImportDeleted(ImportDeleted&&) = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}} 475ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) ImportDeleted& operator=(ImportDeleted&&) = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}} 476ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) void deleted() = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}} 477ef8225444452a1486bd721f3285301fe84643b00Stephen Hines}; 478ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 479ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 4806bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import allocation functions. 4816bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesstruct ImportAlloc { 4826bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) void* operator new(__SIZE_TYPE__); 4836bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) void* operator new[](__SIZE_TYPE__); 4846bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) void operator delete(void*); 4856bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) void operator delete[](void*); 4866bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines}; 4876bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 4886bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 4896bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import defaulted member functions. 4906bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesstruct ImportDefaulted { 4916bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) ImportDefaulted() = default; 4926bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) ~ImportDefaulted() = default; 4936bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) ImportDefaulted(const ImportDefaulted&) = default; 4946bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) ImportDefaulted& operator=(const ImportDefaulted&) = default; 4956bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) ImportDefaulted(ImportDefaulted&&) = default; 4966bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) ImportDefaulted& operator=(ImportDefaulted&&) = default; 4976bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines}; 4986bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 4996bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 5006bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import defaulted member function definitions. 5016bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesstruct ImportDefaultedDefs { 5026bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) ImportDefaultedDefs(); 5036bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) ~ImportDefaultedDefs(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 5046bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 5056bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) inline ImportDefaultedDefs(const ImportDefaultedDefs&); 5066bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) ImportDefaultedDefs& operator=(const ImportDefaultedDefs&); 5076bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 5086bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) ImportDefaultedDefs(ImportDefaultedDefs&&); 5096bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) ImportDefaultedDefs& operator=(ImportDefaultedDefs&&); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 5106bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines}; 5116bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 5126bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Not allowed on definitions. 5136bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) ImportDefaultedDefs::ImportDefaultedDefs() = default; // expected-error{{dllimport cannot be applied to non-inline function definition}} 5146bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 5156bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// dllimport cannot be dropped. 5166bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen HinesImportDefaultedDefs::~ImportDefaultedDefs() = default; // expected-warning{{'ImportDefaultedDefs::~ImportDefaultedDefs' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 5176bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 5186bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import inline declaration and definition. 5196bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) ImportDefaultedDefs::ImportDefaultedDefs(const ImportDefaultedDefs&) = default; 5206bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesinline ImportDefaultedDefs& ImportDefaultedDefs::operator=(const ImportDefaultedDefs&) = default; 5216bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 5226bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) ImportDefaultedDefs::ImportDefaultedDefs(ImportDefaultedDefs&&) = default; // expected-error{{dllimport cannot be applied to non-inline function definition}} 5236bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen HinesImportDefaultedDefs& ImportDefaultedDefs::operator=(ImportDefaultedDefs&&) = default; // expected-warning{{'ImportDefaultedDefs::operator=' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 5246bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 5256bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 5266bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Redeclarations cannot add dllimport. 5276bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesstruct MemberRedecl { 5286bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void normalDef(); // expected-note{{previous declaration is here}} 5296bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void normalInlineDef(); // expected-note{{previous declaration is here}} 5306bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines inline void normalInlineDecl(); // expected-note{{previous declaration is here}} 5316bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines virtual void virtualDef(); // expected-note{{previous declaration is here}} 5326bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines virtual void virtualInlineDef(); // expected-note{{previous declaration is here}} 5336bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines virtual inline void virtualInlineDecl(); // expected-note{{previous declaration is here}} 5346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines static void staticDef(); // expected-note{{previous declaration is here}} 5356bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines static void staticInlineDef(); // expected-note{{previous declaration is here}} 5366bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines static inline void staticInlineDecl(); // expected-note{{previous declaration is here}} 537ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 538ef8225444452a1486bd721f3285301fe84643b00Stephen Hines static int StaticField; // expected-note{{previous declaration is here}} 539ef8225444452a1486bd721f3285301fe84643b00Stephen Hines static const int StaticConstField; // expected-note{{previous declaration is here}} 540ef8225444452a1486bd721f3285301fe84643b00Stephen Hines constexpr static int ConstexprField = 1; // expected-note{{previous declaration is here}} 5416bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines}; 5426bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 5436bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) void MemberRedecl::normalDef() {} // expected-error{{redeclaration of 'MemberRedecl::normalDef' cannot add 'dllimport' attribute}} 5446bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // expected-error@-1{{dllimport cannot be applied to non-inline function definition}} 5456bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) inline void MemberRedecl::normalInlineDef() {} // expected-error{{redeclaration of 'MemberRedecl::normalInlineDef' cannot add 'dllimport' attribute}} 5466bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) void MemberRedecl::normalInlineDecl() {} // expected-error{{redeclaration of 'MemberRedecl::normalInlineDecl' cannot add 'dllimport' attribute}} 5476bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) void MemberRedecl::virtualDef() {} // expected-error{{redeclaration of 'MemberRedecl::virtualDef' cannot add 'dllimport' attribute}} 5486bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // expected-error@-1{{dllimport cannot be applied to non-inline function definition}} 5496bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) inline void MemberRedecl::virtualInlineDef() {} // expected-error{{redeclaration of 'MemberRedecl::virtualInlineDef' cannot add 'dllimport' attribute}} 5506bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) void MemberRedecl::virtualInlineDecl() {} // expected-error{{redeclaration of 'MemberRedecl::virtualInlineDecl' cannot add 'dllimport' attribute}} 5516bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) void MemberRedecl::staticDef() {} // expected-error{{redeclaration of 'MemberRedecl::staticDef' cannot add 'dllimport' attribute}} 5526bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // expected-error@-1{{dllimport cannot be applied to non-inline function definition}} 5536bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) inline void MemberRedecl::staticInlineDef() {} // expected-error{{redeclaration of 'MemberRedecl::staticInlineDef' cannot add 'dllimport' attribute}} 5546bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines__declspec(dllimport) void MemberRedecl::staticInlineDecl() {} // expected-error{{redeclaration of 'MemberRedecl::staticInlineDecl' cannot add 'dllimport' attribute}} 5556bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 556ef8225444452a1486bd721f3285301fe84643b00Stephen Hines__declspec(dllimport) int MemberRedecl::StaticField = 1; // expected-error{{redeclaration of 'MemberRedecl::StaticField' cannot add 'dllimport' attribute}} 557ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-error@-1{{definition of dllimport static field not allowed}} 558ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-note@-2{{attribute is here}} 559ef8225444452a1486bd721f3285301fe84643b00Stephen Hines__declspec(dllimport) const int MemberRedecl::StaticConstField = 1; // expected-error{{redeclaration of 'MemberRedecl::StaticConstField' cannot add 'dllimport' attribute}} 560ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-error@-1{{definition of dllimport static field not allowed}} 561ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-note@-2{{attribute is here}} 562ef8225444452a1486bd721f3285301fe84643b00Stephen Hines__declspec(dllimport) constexpr int MemberRedecl::ConstexprField; // expected-error{{redeclaration of 'MemberRedecl::ConstexprField' cannot add 'dllimport' attribute}} 563ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-error@-1{{definition of dllimport static field not allowed}} 564ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-note@-2{{attribute is here}} 565ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 5666bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 5676bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 5686bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines//===----------------------------------------------------------------------===// 5696bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Class member templates 5706bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines//===----------------------------------------------------------------------===// 5716bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 5726bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesstruct ImportMemberTmpl { 5736bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename T> __declspec(dllimport) void normalDecl(); 5746bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename T> __declspec(dllimport) void normalDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 5756bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename T> __declspec(dllimport) void normalInclass() {} 5766bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename T> __declspec(dllimport) void normalInlineDef(); 5776bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename T> __declspec(dllimport) inline void normalInlineDecl(); 5786bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename T> __declspec(dllimport) static void staticDecl(); 5796bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename T> __declspec(dllimport) static void staticDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 5806bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename T> __declspec(dllimport) static void staticInclass() {} 5816bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename T> __declspec(dllimport) static void staticInlineDef(); 5826bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename T> __declspec(dllimport) static inline void staticInlineDecl(); 583ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 584ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#if __has_feature(cxx_variable_templates) 585ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename T> __declspec(dllimport) static int StaticField; 586ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename T> __declspec(dllimport) static int StaticFieldDef; // expected-note{{attribute is here}} 587ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename T> __declspec(dllimport) static const int StaticConstField; 588ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename T> __declspec(dllimport) static const int StaticConstFieldDef; // expected-note{{attribute is here}} 589ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename T> __declspec(dllimport) static const int StaticConstFieldEqualInit = 1; 590ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename T> __declspec(dllimport) static const int StaticConstFieldBraceInit{1}; 591ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename T> __declspec(dllimport) constexpr static int ConstexprField = 1; 592ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename T> __declspec(dllimport) constexpr static int ConstexprFieldDef = 1; // expected-note{{attribute is here}} 593ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#endif // __has_feature(cxx_variable_templates) 5946bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines}; 5956bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 5966bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> void ImportMemberTmpl::normalDef() {} // expected-warning{{'ImportMemberTmpl::normalDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 5976bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> inline void ImportMemberTmpl::normalInlineDef() {} 5986bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> void ImportMemberTmpl::normalInlineDecl() {} 5996bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> void ImportMemberTmpl::staticDef() {} // expected-warning{{'ImportMemberTmpl::staticDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 6006bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> inline void ImportMemberTmpl::staticInlineDef() {} 6016bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> void ImportMemberTmpl::staticInlineDecl() {} 6026bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 603ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#if __has_feature(cxx_variable_templates) 604ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate<typename T> int ImportMemberTmpl::StaticFieldDef; // expected-error{{definition of dllimport static field not allowed}} 605ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate<typename T> const int ImportMemberTmpl::StaticConstFieldDef = 1; // expected-error{{definition of dllimport static field not allowed}} 606ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate<typename T> constexpr int ImportMemberTmpl::ConstexprFieldDef; // expected-error{{definition of dllimport static field not allowed}} 607ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#endif // __has_feature(cxx_variable_templates) 608ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 6096bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 6106bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Redeclarations cannot add dllimport. 6116bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesstruct MemTmplRedecl { 6126bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename T> void normalDef(); // expected-note{{previous declaration is here}} 6136bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename T> void normalInlineDef(); // expected-note{{previous declaration is here}} 6146bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename T> inline void normalInlineDecl(); // expected-note{{previous declaration is here}} 6156bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename T> static void staticDef(); // expected-note{{previous declaration is here}} 6166bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename T> static void staticInlineDef(); // expected-note{{previous declaration is here}} 6176bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename T> static inline void staticInlineDecl(); // expected-note{{previous declaration is here}} 618ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 619ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#if __has_feature(cxx_variable_templates) 620ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename T> static int StaticField; // expected-note{{previous declaration is here}} 621ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename T> static const int StaticConstField; // expected-note{{previous declaration is here}} 622ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename T> constexpr static int ConstexprField = 1; // expected-note{{previous declaration is here}} 623ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#endif // __has_feature(cxx_variable_templates) 6246bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines}; 6256bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 6266bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) void MemTmplRedecl::normalDef() {} // expected-error{{redeclaration of 'MemTmplRedecl::normalDef' cannot add 'dllimport' attribute}} 6276bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // expected-error@-1{{dllimport cannot be applied to non-inline function definition}} 6286bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) inline void MemTmplRedecl::normalInlineDef() {} // expected-error{{redeclaration of 'MemTmplRedecl::normalInlineDef' cannot add 'dllimport' attribute}} 6296bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) void MemTmplRedecl::normalInlineDecl() {} // expected-error{{redeclaration of 'MemTmplRedecl::normalInlineDecl' cannot add 'dllimport' attribute}} 6306bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) void MemTmplRedecl::staticDef() {} // expected-error{{redeclaration of 'MemTmplRedecl::staticDef' cannot add 'dllimport' attribute}} 6316bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // expected-error@-1{{dllimport cannot be applied to non-inline function definition}} 6326bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) inline void MemTmplRedecl::staticInlineDef() {} // expected-error{{redeclaration of 'MemTmplRedecl::staticInlineDef' cannot add 'dllimport' attribute}} 6336bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) void MemTmplRedecl::staticInlineDecl() {} // expected-error{{redeclaration of 'MemTmplRedecl::staticInlineDecl' cannot add 'dllimport' attribute}} 6346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 635ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#if __has_feature(cxx_variable_templates) 636ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate<typename T> __declspec(dllimport) int MemTmplRedecl::StaticField = 1; // expected-error{{redeclaration of 'MemTmplRedecl::StaticField' cannot add 'dllimport' attribute}} 637ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-error@-1{{definition of dllimport static field not allowed}} 638ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-note@-2{{attribute is here}} 639ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate<typename T> __declspec(dllimport) const int MemTmplRedecl::StaticConstField = 1; // expected-error{{redeclaration of 'MemTmplRedecl::StaticConstField' cannot add 'dllimport' attribute}} 640ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-error@-1{{definition of dllimport static field not allowed}} 641ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-note@-2{{attribute is here}} 642ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate<typename T> __declspec(dllimport) constexpr int MemTmplRedecl::ConstexprField; // expected-error{{redeclaration of 'MemTmplRedecl::ConstexprField' cannot add 'dllimport' attribute}} 643ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-error@-1{{definition of dllimport static field not allowed}} 644ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-note@-2{{attribute is here}} 645ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#endif // __has_feature(cxx_variable_templates) 646ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 6476bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 6486bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 6496bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesstruct MemFunTmpl { 6506bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename T> void normalDef() {} 6516bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename T> __declspec(dllimport) void importedNormal() {} 6526bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename T> static void staticDef() {} 6536bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename T> __declspec(dllimport) static void importedStatic() {} 6546bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines}; 6556bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 6566bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import implicit instantiation of an imported member function template. 6576bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesvoid useMemFunTmpl() { 6586bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines MemFunTmpl().importedNormal<ImplicitInst_Imported>(); 6596bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines MemFunTmpl().importedStatic<ImplicitInst_Imported>(); 6606bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines} 6616bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 6626bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import explicit instantiation declaration of an imported member function 6636bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// template. 6646bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesextern template void MemFunTmpl::importedNormal<ExplicitDecl_Imported>(); 6656bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesextern template void MemFunTmpl::importedStatic<ExplicitDecl_Imported>(); 6666bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 6676bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import explicit instantiation definition of an imported member function 6686bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// template. 6696bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// NB: MSVC fails this instantiation without explicit dllimport. 6706bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate void MemFunTmpl::importedNormal<ExplicitInst_Imported>(); 6716bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate void MemFunTmpl::importedStatic<ExplicitInst_Imported>(); 6726bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 6736bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import specialization of an imported member function template. 6746bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<> __declspec(dllimport) void MemFunTmpl::importedNormal<ExplicitSpec_Imported>(); 6756bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<> __declspec(dllimport) void MemFunTmpl::importedNormal<ExplicitSpec_Def_Imported>() {} // error on mingw 6766bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<> __declspec(dllimport) inline void MemFunTmpl::importedNormal<ExplicitSpec_InlineDef_Imported>() {} 6776bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines#ifndef MSABI 6786bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// expected-error@-3{{dllimport cannot be applied to non-inline function definition}} 6796bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines#endif 6806bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 6816bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<> __declspec(dllimport) void MemFunTmpl::importedStatic<ExplicitSpec_Imported>(); 6826bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<> __declspec(dllimport) void MemFunTmpl::importedStatic<ExplicitSpec_Def_Imported>() {} // error on mingw 6836bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<> __declspec(dllimport) inline void MemFunTmpl::importedStatic<ExplicitSpec_InlineDef_Imported>() {} 6846bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines#ifndef MSABI 6856bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// expected-error@-3{{dllimport cannot be applied to non-inline function definition}} 6866bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines#endif 6876bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 6886bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Not importing specialization of an imported member function template without 6896bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// explicit dllimport. 6906bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<> void MemFunTmpl::importedNormal<ExplicitSpec_NotImported>() {} 6916bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<> void MemFunTmpl::importedStatic<ExplicitSpec_NotImported>() {} 6926bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 6936bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 6946bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import explicit instantiation declaration of a non-imported member function 6956bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// template. 6966bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesextern template __declspec(dllimport) void MemFunTmpl::normalDef<ExplicitDecl_Imported>(); 6976bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesextern template __declspec(dllimport) void MemFunTmpl::staticDef<ExplicitDecl_Imported>(); 6986bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 6996bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import explicit instantiation definition of a non-imported member function 7006bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// template. 7016bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate __declspec(dllimport) void MemFunTmpl::normalDef<ExplicitInst_Imported>(); 7026bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate __declspec(dllimport) void MemFunTmpl::staticDef<ExplicitInst_Imported>(); 7036bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 7046bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import specialization of a non-imported member function template. 7056bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<> __declspec(dllimport) void MemFunTmpl::normalDef<ExplicitSpec_Imported>(); 7066bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<> __declspec(dllimport) void MemFunTmpl::normalDef<ExplicitSpec_Def_Imported>() {} // error on mingw 7076bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<> __declspec(dllimport) inline void MemFunTmpl::normalDef<ExplicitSpec_InlineDef_Imported>() {} 7086bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines#ifndef MSABI 7096bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// expected-error@-3{{dllimport cannot be applied to non-inline function definition}} 7106bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines#endif 7116bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 7126bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<> __declspec(dllimport) void MemFunTmpl::staticDef<ExplicitSpec_Imported>(); 7136bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<> __declspec(dllimport) void MemFunTmpl::staticDef<ExplicitSpec_Def_Imported>() {} // error on mingw 7146bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<> __declspec(dllimport) inline void MemFunTmpl::staticDef<ExplicitSpec_InlineDef_Imported>() {} 7156bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines#ifndef MSABI 7166bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// expected-error@-3{{dllimport cannot be applied to non-inline function definition}} 7176bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines#endif 7186bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 7196bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 7206bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 721ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#if __has_feature(cxx_variable_templates) 722ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesstruct MemVarTmpl { 723ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename T> static const int StaticVar = 1; 724ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename T> __declspec(dllimport) static const int ImportedStaticVar = 1; 725ef8225444452a1486bd721f3285301fe84643b00Stephen Hines}; 726ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 727ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// Import implicit instantiation of an imported member variable template. 728ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesint useMemVarTmpl() { return MemVarTmpl::ImportedStaticVar<ImplicitInst_Imported>; } 729ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 730ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// Import explicit instantiation declaration of an imported member variable 731ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// template. 732ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesextern template const int MemVarTmpl::ImportedStaticVar<ExplicitDecl_Imported>; 733ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 734ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// An explicit instantiation definition of an imported member variable template 735ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// cannot be imported because the template must be defined which is illegal. The 736ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// in-class initializer does not count. 737ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 738ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// Import specialization of an imported member variable template. 739ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate<> __declspec(dllimport) const int MemVarTmpl::ImportedStaticVar<ExplicitSpec_Imported>; 740ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate<> __declspec(dllimport) const int MemVarTmpl::ImportedStaticVar<ExplicitSpec_Def_Imported> = 1; 741ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-error@-1{{definition of dllimport static field not allowed}} 742ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-note@-2{{attribute is here}} 743ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 744ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// Not importing specialization of a member variable template without explicit 745ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// dllimport. 746ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate<> const int MemVarTmpl::ImportedStaticVar<ExplicitSpec_NotImported>; 747ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 748ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 749ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// Import explicit instantiation declaration of a non-imported member variable 750ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// template. 751ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesextern template __declspec(dllimport) const int MemVarTmpl::StaticVar<ExplicitDecl_Imported>; 752ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 753ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// An explicit instantiation definition of a non-imported member variable template 754ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// cannot be imported because the template must be defined which is illegal. The 755ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// in-class initializer does not count. 756ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 757ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// Import specialization of a non-imported member variable template. 758ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate<> __declspec(dllimport) const int MemVarTmpl::StaticVar<ExplicitSpec_Imported>; 759ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate<> __declspec(dllimport) const int MemVarTmpl::StaticVar<ExplicitSpec_Def_Imported> = 1; 760ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-error@-1{{definition of dllimport static field not allowed}} 761ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-note@-2{{attribute is here}} 762ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 763ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#endif // __has_feature(cxx_variable_templates) 764ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 765ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 766ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 7676bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines//===----------------------------------------------------------------------===// 7686bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Class template members 7696bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines//===----------------------------------------------------------------------===// 7706bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 7716bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Import individual members of a class template. 7726bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> 7736bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesstruct ImportClassTmplMembers { 7746bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) void normalDecl(); 7756bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) void normalDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 7766bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) void normalInclass() {} 7776bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) void normalInlineDef(); 7786bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) inline void normalInlineDecl(); 7796bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) virtual void virtualDecl(); 7806bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) virtual void virtualDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 7816bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) virtual void virtualInclass() {} 7826bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) virtual void virtualInlineDef(); 7836bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) virtual inline void virtualInlineDecl(); 7846bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) static void staticDecl(); 7856bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) static void staticDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 7866bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) static void staticInclass() {} 7876bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) static void staticInlineDef(); 7886bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) static inline void staticInlineDecl(); 7896bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 7906bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesprotected: 7916bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) void protectedDecl(); 7926bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesprivate: 7936bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __declspec(dllimport) void privateDecl(); 794ef8225444452a1486bd721f3285301fe84643b00Stephen Hinespublic: 795ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 796ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) int Field; // expected-warning{{'dllimport' attribute only applies to variables, functions and classes}} 797ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) static int StaticField; 798ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) static int StaticFieldDef; // expected-note{{attribute is here}} 799ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) static const int StaticConstField; 800ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) static const int StaticConstFieldDef; // expected-note{{attribute is here}} 801ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) static const int StaticConstFieldEqualInit = 1; 802ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) static const int StaticConstFieldBraceInit{1}; 803ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) constexpr static int ConstexprField = 1; 804ef8225444452a1486bd721f3285301fe84643b00Stephen Hines __declspec(dllimport) constexpr static int ConstexprFieldDef = 1; // expected-note{{attribute is here}} 8056bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines}; 8066bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 8076bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// NB: MSVC is inconsistent here and disallows *InlineDef on class templates, 8086bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// but allows it on classes. We allow both. 8096bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> void ImportClassTmplMembers<T>::normalDef() {} // expected-warning{{'ImportClassTmplMembers::normalDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 8106bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> inline void ImportClassTmplMembers<T>::normalInlineDef() {} 8116bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> void ImportClassTmplMembers<T>::normalInlineDecl() {} 8126bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> void ImportClassTmplMembers<T>::virtualDef() {} // expected-warning{{'ImportClassTmplMembers::virtualDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 8136bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> inline void ImportClassTmplMembers<T>::virtualInlineDef() {} 8146bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> void ImportClassTmplMembers<T>::virtualInlineDecl() {} 8156bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> void ImportClassTmplMembers<T>::staticDef() {} // expected-warning{{'ImportClassTmplMembers::staticDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 8166bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> inline void ImportClassTmplMembers<T>::staticInlineDef() {} 8176bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> void ImportClassTmplMembers<T>::staticInlineDecl() {} 8186bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 819ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate<typename T> int ImportClassTmplMembers<T>::StaticFieldDef; // expected-warning{{definition of dllimport static field}} 820ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate<typename T> const int ImportClassTmplMembers<T>::StaticConstFieldDef = 1; // expected-warning{{definition of dllimport static field}} 821ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate<typename T> constexpr int ImportClassTmplMembers<T>::ConstexprFieldDef; // expected-warning{{definition of dllimport static field}} 822ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 8236bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 8246bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Redeclarations cannot add dllimport. 8256bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> 8266bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesstruct CTMR /*ClassTmplMemberRedecl*/ { 8276bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void normalDef(); // expected-note{{previous declaration is here}} 8286bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void normalInlineDef(); // expected-note{{previous declaration is here}} 8296bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines inline void normalInlineDecl(); // expected-note{{previous declaration is here}} 8306bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines virtual void virtualDef(); // expected-note{{previous declaration is here}} 8316bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines virtual void virtualInlineDef(); // expected-note{{previous declaration is here}} 8326bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines virtual inline void virtualInlineDecl(); // expected-note{{previous declaration is here}} 8336bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines static void staticDef(); // expected-note{{previous declaration is here}} 8346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines static void staticInlineDef(); // expected-note{{previous declaration is here}} 8356bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines static inline void staticInlineDecl(); // expected-note{{previous declaration is here}} 836ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 837ef8225444452a1486bd721f3285301fe84643b00Stephen Hines static int StaticField; // expected-note{{previous declaration is here}} 838ef8225444452a1486bd721f3285301fe84643b00Stephen Hines static const int StaticConstField; // expected-note{{previous declaration is here}} 839ef8225444452a1486bd721f3285301fe84643b00Stephen Hines constexpr static int ConstexprField = 1; // expected-note{{previous declaration is here}} 8406bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines}; 8416bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 8426bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) void CTMR<T>::normalDef() {} // expected-error{{redeclaration of 'CTMR::normalDef' cannot add 'dllimport' attribute}} 8436bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // expected-error@-1{{dllimport cannot be applied to non-inline function definition}} 8446bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) inline void CTMR<T>::normalInlineDef() {} // expected-error{{redeclaration of 'CTMR::normalInlineDef' cannot add 'dllimport' attribute}} 8456bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) void CTMR<T>::normalInlineDecl() {} // expected-error{{redeclaration of 'CTMR::normalInlineDecl' cannot add 'dllimport' attribute}} 8466bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) void CTMR<T>::virtualDef() {} // expected-error{{redeclaration of 'CTMR::virtualDef' cannot add 'dllimport' attribute}} 8476bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // expected-error@-1{{dllimport cannot be applied to non-inline function definition}} 8486bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) inline void CTMR<T>::virtualInlineDef() {} // expected-error{{redeclaration of 'CTMR::virtualInlineDef' cannot add 'dllimport' attribute}} 8496bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) void CTMR<T>::virtualInlineDecl() {} // expected-error{{redeclaration of 'CTMR::virtualInlineDecl' cannot add 'dllimport' attribute}} 8506bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) void CTMR<T>::staticDef() {} // expected-error{{redeclaration of 'CTMR::staticDef' cannot add 'dllimport' attribute}} 8516bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // expected-error@-1{{dllimport cannot be applied to non-inline function definition}} 8526bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) inline void CTMR<T>::staticInlineDef() {} // expected-error{{redeclaration of 'CTMR::staticInlineDef' cannot add 'dllimport' attribute}} 8536bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> __declspec(dllimport) void CTMR<T>::staticInlineDecl() {} // expected-error{{redeclaration of 'CTMR::staticInlineDecl' cannot add 'dllimport' attribute}} 8546bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 855ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate<typename T> __declspec(dllimport) int CTMR<T>::StaticField = 1; // expected-error{{redeclaration of 'CTMR::StaticField' cannot add 'dllimport' attribute}} 856ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-warning@-1{{definition of dllimport static field}} 857ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-note@-2{{attribute is here}} 858ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate<typename T> __declspec(dllimport) const int CTMR<T>::StaticConstField = 1; // expected-error{{redeclaration of 'CTMR::StaticConstField' cannot add 'dllimport' attribute}} 859ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-warning@-1{{definition of dllimport static field}} 860ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-note@-2{{attribute is here}} 861ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate<typename T> __declspec(dllimport) constexpr int CTMR<T>::ConstexprField; // expected-error{{redeclaration of 'CTMR::ConstexprField' cannot add 'dllimport' attribute}} 862ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-warning@-1{{definition of dllimport static field}} 863ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-note@-2{{attribute is here}} 864ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 8656bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 8666bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 8676bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines//===----------------------------------------------------------------------===// 8686bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Class template member templates 8696bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines//===----------------------------------------------------------------------===// 8706bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 8716bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> 8726bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesstruct ImportClsTmplMemTmpl { 8736bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename U> __declspec(dllimport) void normalDecl(); 8746bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename U> __declspec(dllimport) void normalDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 8756bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename U> __declspec(dllimport) void normalInclass() {} 8766bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename U> __declspec(dllimport) void normalInlineDef(); 8776bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename U> __declspec(dllimport) inline void normalInlineDecl(); 8786bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename U> __declspec(dllimport) static void staticDecl(); 8796bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename U> __declspec(dllimport) static void staticDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} 8806bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename U> __declspec(dllimport) static void staticInclass() {} 8816bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename U> __declspec(dllimport) static void staticInlineDef(); 8826bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename U> __declspec(dllimport) static inline void staticInlineDecl(); 883ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 884ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#if __has_feature(cxx_variable_templates) 885ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename U> __declspec(dllimport) static int StaticField; 886ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename U> __declspec(dllimport) static int StaticFieldDef; // expected-note{{attribute is here}} 887ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename U> __declspec(dllimport) static const int StaticConstField; 888ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename U> __declspec(dllimport) static const int StaticConstFieldDef; // expected-note{{attribute is here}} 889ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename U> __declspec(dllimport) static const int StaticConstFieldEqualInit = 1; 890ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename U> __declspec(dllimport) static const int StaticConstFieldBraceInit{1}; 891ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename U> __declspec(dllimport) constexpr static int ConstexprField = 1; 892ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename U> __declspec(dllimport) constexpr static int ConstexprFieldDef = 1; // expected-note{{attribute is here}} 893ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#endif // __has_feature(cxx_variable_templates) 8946bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines}; 8956bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 8966bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> template<typename U> void ImportClsTmplMemTmpl<T>::normalDef() {} // expected-warning{{'ImportClsTmplMemTmpl::normalDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 8976bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> template<typename U> inline void ImportClsTmplMemTmpl<T>::normalInlineDef() {} 8986bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> template<typename U> void ImportClsTmplMemTmpl<T>::normalInlineDecl() {} 8996bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> template<typename U> void ImportClsTmplMemTmpl<T>::staticDef() {} // expected-warning{{'ImportClsTmplMemTmpl::staticDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} 9006bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> template<typename U> inline void ImportClsTmplMemTmpl<T>::staticInlineDef() {} 9016bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> template<typename U> void ImportClsTmplMemTmpl<T>::staticInlineDecl() {} 9026bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 903ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#if __has_feature(cxx_variable_templates) 904ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate<typename T> template<typename U> int ImportClsTmplMemTmpl<T>::StaticFieldDef; // expected-warning{{definition of dllimport static field}} 905ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate<typename T> template<typename U> const int ImportClsTmplMemTmpl<T>::StaticConstFieldDef = 1; // expected-warning{{definition of dllimport static field}} 906ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate<typename T> template<typename U> constexpr int ImportClsTmplMemTmpl<T>::ConstexprFieldDef; // expected-warning{{definition of dllimport static field}} 907ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#endif // __has_feature(cxx_variable_templates) 908ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 9096bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 9106bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Redeclarations cannot add dllimport. 9116bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> 9126bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesstruct CTMTR /*ClassTmplMemberTmplRedecl*/ { 9136bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename U> void normalDef(); // expected-note{{previous declaration is here}} 9146bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename U> void normalInlineDef(); // expected-note{{previous declaration is here}} 9156bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename U> inline void normalInlineDecl(); // expected-note{{previous declaration is here}} 9166bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename U> static void staticDef(); // expected-note{{previous declaration is here}} 9176bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename U> static void staticInlineDef(); // expected-note{{previous declaration is here}} 9186bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines template<typename U> static inline void staticInlineDecl(); // expected-note{{previous declaration is here}} 919ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 920ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#if __has_feature(cxx_variable_templates) 921ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename U> static int StaticField; // expected-note{{previous declaration is here}} 922ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename U> static const int StaticConstField; // expected-note{{previous declaration is here}} 923ef8225444452a1486bd721f3285301fe84643b00Stephen Hines template<typename U> constexpr static int ConstexprField = 1; // expected-note{{previous declaration is here}} 924ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#endif // __has_feature(cxx_variable_templates) 9256bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines}; 9266bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 9276bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> template<typename U> __declspec(dllimport) void CTMTR<T>::normalDef() {} // expected-error{{redeclaration of 'CTMTR::normalDef' cannot add 'dllimport' attribute}} 9286bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // expected-error@-1{{dllimport cannot be applied to non-inline function definition}} 9296bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> template<typename U> __declspec(dllimport) inline void CTMTR<T>::normalInlineDef() {} // expected-error{{redeclaration of 'CTMTR::normalInlineDef' cannot add 'dllimport' attribute}} 9306bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> template<typename U> __declspec(dllimport) void CTMTR<T>::normalInlineDecl() {} // expected-error{{redeclaration of 'CTMTR::normalInlineDecl' cannot add 'dllimport' attribute}} 9316bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> template<typename U> __declspec(dllimport) void CTMTR<T>::staticDef() {} // expected-error{{redeclaration of 'CTMTR::staticDef' cannot add 'dllimport' attribute}} 9326bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // expected-error@-1{{dllimport cannot be applied to non-inline function definition}} 9336bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> template<typename U> __declspec(dllimport) inline void CTMTR<T>::staticInlineDef() {} // expected-error{{redeclaration of 'CTMTR::staticInlineDef' cannot add 'dllimport' attribute}} 9346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestemplate<typename T> template<typename U> __declspec(dllimport) void CTMTR<T>::staticInlineDecl() {} // expected-error{{redeclaration of 'CTMTR::staticInlineDecl' cannot add 'dllimport' attribute}} 935ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 936ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#if __has_feature(cxx_variable_templates) 937ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate<typename T> template<typename U> __declspec(dllimport) int CTMTR<T>::StaticField = 1; // expected-error{{redeclaration of 'CTMTR::StaticField' cannot add 'dllimport' attribute}} 938ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-warning@-1{{definition of dllimport static field}} 939ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-note@-2{{attribute is here}} 940ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate<typename T> template<typename U> __declspec(dllimport) const int CTMTR<T>::StaticConstField = 1; // expected-error{{redeclaration of 'CTMTR::StaticConstField' cannot add 'dllimport' attribute}} 941ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-warning@-1{{definition of dllimport static field}} 942ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-note@-2{{attribute is here}} 943ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate<typename T> template<typename U> __declspec(dllimport) constexpr int CTMTR<T>::ConstexprField; // expected-error{{redeclaration of 'CTMTR::ConstexprField' cannot add 'dllimport' attribute}} 944ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-warning@-1{{definition of dllimport static field}} 945ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // expected-note@-2{{attribute is here}} 946ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#endif // __has_feature(cxx_variable_templates) 947ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 948ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 949ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 950ef8225444452a1486bd721f3285301fe84643b00Stephen Hines//===----------------------------------------------------------------------===// 951ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// Classes 952ef8225444452a1486bd721f3285301fe84643b00Stephen Hines//===----------------------------------------------------------------------===// 953ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 954ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesclass __declspec(dllimport) ClassDecl; 955ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 956ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesclass __declspec(dllimport) ClassDef { }; 957ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 958ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate <typename T> class ClassTemplate {}; 959ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 960ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#ifdef MS 961ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// expected-note@+5{{previous attribute is here}} 962ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// expected-note@+4{{previous attribute is here}} 963ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// expected-error@+4{{attribute 'dllexport' cannot be applied to member of 'dllimport' class}} 964ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// expected-error@+4{{attribute 'dllimport' cannot be applied to member of 'dllimport' class}} 965ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#endif 966ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesclass __declspec(dllimport) ImportClassWithDllMember { 967ef8225444452a1486bd721f3285301fe84643b00Stephen Hines void __declspec(dllexport) foo(); 968ef8225444452a1486bd721f3285301fe84643b00Stephen Hines void __declspec(dllimport) bar(); 969ef8225444452a1486bd721f3285301fe84643b00Stephen Hines}; 970ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 971ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#ifdef MS 972ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// expected-note@+5{{previous attribute is here}} 973ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// expected-note@+4{{previous attribute is here}} 974ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// expected-error@+4{{attribute 'dllimport' cannot be applied to member of 'dllexport' class}} 975ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// expected-error@+4{{attribute 'dllexport' cannot be applied to member of 'dllexport' class}} 976ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#endif 977ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesclass __declspec(dllexport) ExportClassWithDllMember { 978ef8225444452a1486bd721f3285301fe84643b00Stephen Hines void __declspec(dllimport) foo(); 979ef8225444452a1486bd721f3285301fe84643b00Stephen Hines void __declspec(dllexport) bar(); 980ef8225444452a1486bd721f3285301fe84643b00Stephen Hines}; 981ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 982ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesnamespace ImportedExplicitSpecialization { 983ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate <typename T> struct S { static int x; }; 984ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate <typename T> int S<T>::x = sizeof(T); 985ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate <> struct __declspec(dllimport) S<int> { static int x; }; // expected-note{{attribute is here}} 986ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesint S<int>::x = -1; // expected-error{{definition of dllimport static field not allowed}} 987ef8225444452a1486bd721f3285301fe84643b00Stephen Hines} 988ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 989ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesnamespace PR19988 { 990ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// Don't error about applying delete to dllimport member function when instantiating. 991ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate <typename> struct __declspec(dllimport) S { 992ef8225444452a1486bd721f3285301fe84643b00Stephen Hines void foo() = delete; 993ef8225444452a1486bd721f3285301fe84643b00Stephen Hines}; 994ef8225444452a1486bd721f3285301fe84643b00Stephen HinesS<int> s; 995ef8225444452a1486bd721f3285301fe84643b00Stephen Hines} 996ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 997ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#ifdef MS 998ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// expected-warning@+3{{'dllimport' attribute ignored}} 999ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#endif 1000ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate <typename T> struct PartiallySpecializedClassTemplate {}; 1001ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate <typename T> struct __declspec(dllimport) PartiallySpecializedClassTemplate<T*> { void f() {} }; 1002ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 1003ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate <typename T> struct ExpliciallySpecializedClassTemplate {}; 1004ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate <> struct __declspec(dllimport) ExpliciallySpecializedClassTemplate<int> { void f() {} }; 1005ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 1006ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 1007ef8225444452a1486bd721f3285301fe84643b00Stephen Hines//===----------------------------------------------------------------------===// 1008ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// Classes with template base classes 1009ef8225444452a1486bd721f3285301fe84643b00Stephen Hines//===----------------------------------------------------------------------===// 1010ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 1011ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate <typename T> class __declspec(dllexport) ExportedClassTemplate {}; 1012ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 1013ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate <typename T> class __declspec(dllimport) ImportedClassTemplate {}; 1014ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 1015ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// ClassTemplate<int> gets imported. 1016ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesclass __declspec(dllimport) DerivedFromTemplate : public ClassTemplate<int> {}; 1017ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 1018ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// ClassTemplate<int> is already imported. 1019ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesclass __declspec(dllimport) DerivedFromTemplate2 : public ClassTemplate<int> {}; 1020ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 1021ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// ImportedClassTemplate is expliitly imported. 1022ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesclass __declspec(dllimport) DerivedFromImportedTemplate : public ImportedClassTemplate<int> {}; 1023ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 1024ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// ExportedClassTemplate is explicitly exported. 1025ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesclass __declspec(dllimport) DerivedFromExportedTemplate : public ExportedClassTemplate<int> {}; 1026ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 1027ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#ifdef MS 1028ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// expected-note@+4{{class template 'ClassTemplate<double>' was instantiated here}} 1029ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// expected-warning@+4{{propagating dll attribute to already instantiated base class template without dll attribute is unsupported}} 1030ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// expected-note@+3{{attribute is here}} 1031ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#endif 1032ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesclass DerivedFromTemplateD : public ClassTemplate<double> {}; 1033ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesclass __declspec(dllimport) DerivedFromTemplateD2 : public ClassTemplate<double> {}; 1034ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 1035ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#ifdef MS 1036ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// expected-note@+4{{class template 'ClassTemplate<bool>' was instantiated here}} 1037ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// expected-warning@+4{{propagating dll attribute to already instantiated base class template with different dll attribute is unsupported}} 1038ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// expected-note@+3{{attribute is here}} 1039ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#endif 1040ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesclass __declspec(dllexport) DerivedFromTemplateB : public ClassTemplate<bool> {}; 1041ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesclass __declspec(dllimport) DerivedFromTemplateB2 : public ClassTemplate<bool> {}; 1042ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 1043ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate <typename T> struct ExplicitlySpecializedTemplate { void func() {} }; 1044ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#ifdef MS 1045ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// expected-note@+2{{class template 'ExplicitlySpecializedTemplate<int>' was explicitly specialized here}} 1046ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#endif 1047ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate <> struct ExplicitlySpecializedTemplate<int> { void func() {} }; 1048ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate <typename T> struct ExplicitlyExportSpecializedTemplate { void func() {} }; 1049ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate <> struct __declspec(dllexport) ExplicitlyExportSpecializedTemplate<int> { void func() {} }; 1050ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate <typename T> struct ExplicitlyImportSpecializedTemplate { void func() {} }; 1051ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate <> struct __declspec(dllimport) ExplicitlyImportSpecializedTemplate<int> { void func() {} }; 1052ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 1053ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate <typename T> struct ExplicitlyInstantiatedTemplate { void func() {} }; 1054ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#ifdef MS 1055ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// expected-note@+2{{class template 'ExplicitlyInstantiatedTemplate<int>' was instantiated here}} 1056ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#endif 1057ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate struct ExplicitlyInstantiatedTemplate<int>; 1058ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate <typename T> struct ExplicitlyExportInstantiatedTemplate { void func() {} }; 1059ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate struct __declspec(dllexport) ExplicitlyExportInstantiatedTemplate<int>; 1060ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate <typename T> struct ExplicitlyImportInstantiatedTemplate { void func() {} }; 1061ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestemplate struct __declspec(dllimport) ExplicitlyImportInstantiatedTemplate<int>; 1062ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 1063ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#ifdef MS 1064ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// expected-warning@+3{{propagating dll attribute to explicitly specialized base class template without dll attribute is unsupported}} 1065ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// expected-note@+2{{attribute is here}} 1066ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#endif 1067ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesstruct __declspec(dllimport) DerivedFromExplicitlySpecializedTemplate : public ExplicitlySpecializedTemplate<int> {}; 1068ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 1069ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// Base class already specialized with export attribute. 1070ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesstruct __declspec(dllimport) DerivedFromExplicitlyExportSpecializedTemplate : public ExplicitlyExportSpecializedTemplate<int> {}; 1071ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 1072ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// Base class already specialized with import attribute. 1073ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesstruct __declspec(dllimport) DerivedFromExplicitlyImportSpecializedTemplate : public ExplicitlyImportSpecializedTemplate<int> {}; 1074ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 1075ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#ifdef MS 1076ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// expected-warning@+3{{propagating dll attribute to already instantiated base class template without dll attribute is unsupported}} 1077ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// expected-note@+2{{attribute is here}} 1078ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#endif 1079ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesstruct __declspec(dllimport) DerivedFromExplicitlyInstantiatedTemplate : public ExplicitlyInstantiatedTemplate<int> {}; 1080ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 1081ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// Base class already instantiated with export attribute. 1082ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesstruct __declspec(dllimport) DerivedFromExplicitlyExportInstantiatedTemplate : public ExplicitlyExportInstantiatedTemplate<int> {}; 1083ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 1084ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// Base class already instantiated with import attribute. 1085ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesstruct __declspec(dllimport) DerivedFromExplicitlyImportInstantiatedTemplate : public ExplicitlyImportInstantiatedTemplate<int> {}; 1086