From: Nico Rieck Date: Sun, 25 May 2014 10:35:03 +0000 (+0000) Subject: Sema: Add dll attribute tests for member functions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1421a2003a3b874200e4a9c11f546accfed51988;p=clang Sema: Add dll attribute tests for member functions git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209598 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index ad5d7e740b..0215486175 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -2035,7 +2035,7 @@ def err_attribute_aligned_not_power_of_two : Error< def err_attribute_aligned_too_great : Error< "requested alignment must be %0 bytes or smaller">; def warn_redeclaration_without_attribute_prev_attribute_ignored : Warning< - "%0 redeclared without %1 attribute: previous %1 ignored">; + "%q0 redeclared without %1 attribute: previous %1 ignored">; def warn_attribute_ignored : Warning<"%0 attribute ignored">, InGroup; def warn_attribute_after_definition_ignored : Warning< diff --git a/test/SemaCXX/dllexport.cpp b/test/SemaCXX/dllexport.cpp index c9b8bc8312..c361c4991f 100644 --- a/test/SemaCXX/dllexport.cpp +++ b/test/SemaCXX/dllexport.cpp @@ -346,3 +346,391 @@ void __declspec(dllexport) precedenceRedecl1() {} void __declspec(dllexport) precedenceRedecl2(); void __declspec(dllimport) precedenceRedecl2() {} // expected-warning{{'dllimport' attribute ignored}} + + + +//===----------------------------------------------------------------------===// +// Class members +//===----------------------------------------------------------------------===// + +// Export individual members of a class. +struct ExportMembers { + struct Nested { + __declspec(dllexport) void normalDef(); + }; + + __declspec(dllexport) void normalDecl(); + __declspec(dllexport) void normalDef(); + __declspec(dllexport) void normalInclass() {} + __declspec(dllexport) void normalInlineDef(); + __declspec(dllexport) inline void normalInlineDecl(); + __declspec(dllexport) virtual void virtualDecl(); + __declspec(dllexport) virtual void virtualDef(); + __declspec(dllexport) virtual void virtualInclass() {} + __declspec(dllexport) virtual void virtualInlineDef(); + __declspec(dllexport) virtual inline void virtualInlineDecl(); + __declspec(dllexport) static void staticDecl(); + __declspec(dllexport) static void staticDef(); + __declspec(dllexport) static void staticInclass() {} + __declspec(dllexport) static void staticInlineDef(); + __declspec(dllexport) static inline void staticInlineDecl(); + +protected: + __declspec(dllexport) void protectedDef(); +private: + __declspec(dllexport) void privateDef(); +}; + + void ExportMembers::Nested::normalDef() {} + void ExportMembers::normalDef() {} +inline void ExportMembers::normalInlineDef() {} + void ExportMembers::normalInlineDecl() {} + void ExportMembers::virtualDef() {} +inline void ExportMembers::virtualInlineDef() {} + void ExportMembers::virtualInlineDecl() {} + void ExportMembers::staticDef() {} +inline void ExportMembers::staticInlineDef() {} + void ExportMembers::staticInlineDecl() {} + void ExportMembers::protectedDef() {} + void ExportMembers::privateDef() {} + + +// Export on member definitions. +struct ExportMemberDefs { + __declspec(dllexport) void normalDef(); + __declspec(dllexport) void normalInlineDef(); + __declspec(dllexport) inline void normalInlineDecl(); + __declspec(dllexport) virtual void virtualDef(); + __declspec(dllexport) virtual void virtualInlineDef(); + __declspec(dllexport) virtual inline void virtualInlineDecl(); + __declspec(dllexport) static void staticDef(); + __declspec(dllexport) static void staticInlineDef(); + __declspec(dllexport) static inline void staticInlineDecl(); +}; + +__declspec(dllexport) void ExportMemberDefs::normalDef() {} +__declspec(dllexport) inline void ExportMemberDefs::normalInlineDef() {} +__declspec(dllexport) void ExportMemberDefs::normalInlineDecl() {} +__declspec(dllexport) void ExportMemberDefs::virtualDef() {} +__declspec(dllexport) inline void ExportMemberDefs::virtualInlineDef() {} +__declspec(dllexport) void ExportMemberDefs::virtualInlineDecl() {} +__declspec(dllexport) void ExportMemberDefs::staticDef() {} +__declspec(dllexport) inline void ExportMemberDefs::staticInlineDef() {} +__declspec(dllexport) void ExportMemberDefs::staticInlineDecl() {} + + +// Export special member functions. +struct ExportSpecials { + __declspec(dllexport) ExportSpecials() {} + __declspec(dllexport) ~ExportSpecials(); + __declspec(dllexport) inline ExportSpecials(const ExportSpecials&); + __declspec(dllexport) ExportSpecials& operator=(const ExportSpecials&); + __declspec(dllexport) ExportSpecials(ExportSpecials&&); + __declspec(dllexport) ExportSpecials& operator=(ExportSpecials&&); +}; + +ExportSpecials::~ExportSpecials() {} +ExportSpecials::ExportSpecials(const ExportSpecials&) {} +inline ExportSpecials& ExportSpecials::operator=(const ExportSpecials&) { return *this; } +ExportSpecials::ExportSpecials(ExportSpecials&&) {} +ExportSpecials& ExportSpecials::operator=(ExportSpecials&&) { return *this; } + + +// Export allocation functions. +extern "C" void* malloc(__SIZE_TYPE__ size); +extern "C" void free(void* p); +struct ExportAlloc { + __declspec(dllexport) void* operator new(__SIZE_TYPE__); + __declspec(dllexport) void* operator new[](__SIZE_TYPE__); + __declspec(dllexport) void operator delete(void*); + __declspec(dllexport) void operator delete[](void*); +}; +void* ExportAlloc::operator new(__SIZE_TYPE__ n) { return malloc(n); } +void* ExportAlloc::operator new[](__SIZE_TYPE__ n) { return malloc(n); } +void ExportAlloc::operator delete(void* p) { free(p); } +void ExportAlloc::operator delete[](void* p) { free(p); } + + +// Export defaulted member functions. +struct ExportDefaulted { + __declspec(dllexport) ExportDefaulted() = default; + __declspec(dllexport) ~ExportDefaulted() = default; + __declspec(dllexport) ExportDefaulted(const ExportDefaulted&) = default; + __declspec(dllexport) ExportDefaulted& operator=(const ExportDefaulted&) = default; + __declspec(dllexport) ExportDefaulted(ExportDefaulted&&) = default; + __declspec(dllexport) ExportDefaulted& operator=(ExportDefaulted&&) = default; +}; + + +// Export defaulted member function definitions. +struct ExportDefaultedDefs { + __declspec(dllexport) ExportDefaultedDefs(); + __declspec(dllexport) ~ExportDefaultedDefs(); + + __declspec(dllexport) inline ExportDefaultedDefs(const ExportDefaultedDefs&); + __declspec(dllexport) ExportDefaultedDefs& operator=(const ExportDefaultedDefs&); + + __declspec(dllexport) ExportDefaultedDefs(ExportDefaultedDefs&&); + __declspec(dllexport) ExportDefaultedDefs& operator=(ExportDefaultedDefs&&); +}; + +// Export definitions. +__declspec(dllexport) ExportDefaultedDefs::ExportDefaultedDefs() = default; +ExportDefaultedDefs::~ExportDefaultedDefs() = default; + +// Export inline declaration and definition. +__declspec(dllexport) ExportDefaultedDefs::ExportDefaultedDefs(const ExportDefaultedDefs&) = default; +inline ExportDefaultedDefs& ExportDefaultedDefs::operator=(const ExportDefaultedDefs&) = default; + +__declspec(dllexport) ExportDefaultedDefs::ExportDefaultedDefs(ExportDefaultedDefs&&) = default; +ExportDefaultedDefs& ExportDefaultedDefs::operator=(ExportDefaultedDefs&&) = default; + + +// Redeclarations cannot add dllexport. +struct MemberRedecl { + void normalDef(); // expected-note{{previous declaration is here}} + void normalInlineDef(); // expected-note{{previous declaration is here}} + inline void normalInlineDecl(); // expected-note{{previous declaration is here}} + virtual void virtualDef(); // expected-note{{previous declaration is here}} + virtual void virtualInlineDef(); // expected-note{{previous declaration is here}} + virtual inline void virtualInlineDecl(); // expected-note{{previous declaration is here}} + static void staticDef(); // expected-note{{previous declaration is here}} + static void staticInlineDef(); // expected-note{{previous declaration is here}} + static inline void staticInlineDecl(); // expected-note{{previous declaration is here}} +}; + +__declspec(dllexport) void MemberRedecl::normalDef() {} // expected-error{{redeclaration of 'MemberRedecl::normalDef' cannot add 'dllexport' attribute}} +__declspec(dllexport) inline void MemberRedecl::normalInlineDef() {} // expected-error{{redeclaration of 'MemberRedecl::normalInlineDef' cannot add 'dllexport' attribute}} +__declspec(dllexport) void MemberRedecl::normalInlineDecl() {} // expected-error{{redeclaration of 'MemberRedecl::normalInlineDecl' cannot add 'dllexport' attribute}} +__declspec(dllexport) void MemberRedecl::virtualDef() {} // expected-error{{redeclaration of 'MemberRedecl::virtualDef' cannot add 'dllexport' attribute}} +__declspec(dllexport) inline void MemberRedecl::virtualInlineDef() {} // expected-error{{redeclaration of 'MemberRedecl::virtualInlineDef' cannot add 'dllexport' attribute}} +__declspec(dllexport) void MemberRedecl::virtualInlineDecl() {} // expected-error{{redeclaration of 'MemberRedecl::virtualInlineDecl' cannot add 'dllexport' attribute}} +__declspec(dllexport) void MemberRedecl::staticDef() {} // expected-error{{redeclaration of 'MemberRedecl::staticDef' cannot add 'dllexport' attribute}} +__declspec(dllexport) inline void MemberRedecl::staticInlineDef() {} // expected-error{{redeclaration of 'MemberRedecl::staticInlineDef' cannot add 'dllexport' attribute}} +__declspec(dllexport) void MemberRedecl::staticInlineDecl() {} // expected-error{{redeclaration of 'MemberRedecl::staticInlineDecl' cannot add 'dllexport' attribute}} + + + +//===----------------------------------------------------------------------===// +// Class member templates +//===----------------------------------------------------------------------===// + +struct ExportMemberTmpl { + template __declspec(dllexport) void normalDecl(); + template __declspec(dllexport) void normalDef(); + template __declspec(dllexport) void normalInclass() {} + template __declspec(dllexport) void normalInlineDef(); + template __declspec(dllexport) inline void normalInlineDecl(); + template __declspec(dllexport) static void staticDecl(); + template __declspec(dllexport) static void staticDef(); + template __declspec(dllexport) static void staticInclass() {} + template __declspec(dllexport) static void staticInlineDef(); + template __declspec(dllexport) static inline void staticInlineDecl(); +}; + +template void ExportMemberTmpl::normalDef() {} +template inline void ExportMemberTmpl::normalInlineDef() {} +template void ExportMemberTmpl::normalInlineDecl() {} +template void ExportMemberTmpl::staticDef() {} +template inline void ExportMemberTmpl::staticInlineDef() {} +template void ExportMemberTmpl::staticInlineDecl() {} + + + +// Redeclarations cannot add dllexport. +struct MemTmplRedecl { + template void normalDef(); // expected-note{{previous declaration is here}} + template void normalInlineDef(); // expected-note{{previous declaration is here}} + template inline void normalInlineDecl(); // expected-note{{previous declaration is here}} + template static void staticDef(); // expected-note{{previous declaration is here}} + template static void staticInlineDef(); // expected-note{{previous declaration is here}} + template static inline void staticInlineDecl(); // expected-note{{previous declaration is here}} +}; + +template __declspec(dllexport) void MemTmplRedecl::normalDef() {} // expected-error{{redeclaration of 'MemTmplRedecl::normalDef' cannot add 'dllexport' attribute}} +template __declspec(dllexport) inline void MemTmplRedecl::normalInlineDef() {} // expected-error{{redeclaration of 'MemTmplRedecl::normalInlineDef' cannot add 'dllexport' attribute}} +template __declspec(dllexport) void MemTmplRedecl::normalInlineDecl() {} // expected-error{{redeclaration of 'MemTmplRedecl::normalInlineDecl' cannot add 'dllexport' attribute}} +template __declspec(dllexport) void MemTmplRedecl::staticDef() {} // expected-error{{redeclaration of 'MemTmplRedecl::staticDef' cannot add 'dllexport' attribute}} +template __declspec(dllexport) inline void MemTmplRedecl::staticInlineDef() {} // expected-error{{redeclaration of 'MemTmplRedecl::staticInlineDef' cannot add 'dllexport' attribute}} +template __declspec(dllexport) void MemTmplRedecl::staticInlineDecl() {} // expected-error{{redeclaration of 'MemTmplRedecl::staticInlineDecl' cannot add 'dllexport' attribute}} + + + +struct MemFunTmpl { + template void normalDef() {} + template __declspec(dllexport) void exportedNormal() {} + template static void staticDef() {} + template __declspec(dllexport) static void exportedStatic() {} +}; + +// Export implicit instantiation of an exported member function template. +void useMemFunTmpl() { + MemFunTmpl().exportedNormal(); + MemFunTmpl().exportedStatic(); +} + +// Export explicit instantiation declaration of an exported member function +// template. +extern template void MemFunTmpl::exportedNormal(); + template void MemFunTmpl::exportedNormal(); + +extern template void MemFunTmpl::exportedStatic(); + template void MemFunTmpl::exportedStatic(); + +// Export explicit instantiation definition of an exported member function +// template. +template void MemFunTmpl::exportedNormal(); +template void MemFunTmpl::exportedStatic(); + +// Export specialization of an exported member function template. +template<> __declspec(dllexport) void MemFunTmpl::exportedNormal(); +template<> __declspec(dllexport) void MemFunTmpl::exportedNormal() {} +template<> __declspec(dllexport) inline void MemFunTmpl::exportedNormal() {} + +template<> __declspec(dllexport) void MemFunTmpl::exportedStatic(); +template<> __declspec(dllexport) void MemFunTmpl::exportedStatic() {} +template<> __declspec(dllexport) inline void MemFunTmpl::exportedStatic() {} + +// Not exporting specialization of an exported member function template without +// explicit dllexport. +template<> void MemFunTmpl::exportedNormal() {} +template<> void MemFunTmpl::exportedStatic() {} + + +// Export explicit instantiation declaration of a non-exported member function +// template. +extern template __declspec(dllexport) void MemFunTmpl::normalDef(); + template __declspec(dllexport) void MemFunTmpl::normalDef(); + +extern template __declspec(dllexport) void MemFunTmpl::staticDef(); + template __declspec(dllexport) void MemFunTmpl::staticDef(); + +// Export explicit instantiation definition of a non-exported member function +// template. +template __declspec(dllexport) void MemFunTmpl::normalDef(); +template __declspec(dllexport) void MemFunTmpl::staticDef(); + +// Export specialization of a non-exported member function template. +template<> __declspec(dllexport) void MemFunTmpl::normalDef(); +template<> __declspec(dllexport) void MemFunTmpl::normalDef() {} +template<> __declspec(dllexport) inline void MemFunTmpl::normalDef() {} + +template<> __declspec(dllexport) void MemFunTmpl::staticDef(); +template<> __declspec(dllexport) void MemFunTmpl::staticDef() {} +template<> __declspec(dllexport) inline void MemFunTmpl::staticDef() {} + + + +//===----------------------------------------------------------------------===// +// Class template members +//===----------------------------------------------------------------------===// + +// Export individual members of a class template. +template +struct ExportClassTmplMembers { + __declspec(dllexport) void normalDecl(); + __declspec(dllexport) void normalDef(); + __declspec(dllexport) void normalInclass() {} + __declspec(dllexport) void normalInlineDef(); + __declspec(dllexport) inline void normalInlineDecl(); + __declspec(dllexport) virtual void virtualDecl(); + __declspec(dllexport) virtual void virtualDef(); + __declspec(dllexport) virtual void virtualInclass() {} + __declspec(dllexport) virtual void virtualInlineDef(); + __declspec(dllexport) virtual inline void virtualInlineDecl(); + __declspec(dllexport) static void staticDecl(); + __declspec(dllexport) static void staticDef(); + __declspec(dllexport) static void staticInclass() {} + __declspec(dllexport) static void staticInlineDef(); + __declspec(dllexport) static inline void staticInlineDecl(); + +protected: + __declspec(dllexport) void protectedDef(); +private: + __declspec(dllexport) void privateDef(); +}; + +template void ExportClassTmplMembers::normalDef() {} +template inline void ExportClassTmplMembers::normalInlineDef() {} +template void ExportClassTmplMembers::normalInlineDecl() {} +template void ExportClassTmplMembers::virtualDef() {} +template inline void ExportClassTmplMembers::virtualInlineDef() {} +template void ExportClassTmplMembers::virtualInlineDecl() {} +template void ExportClassTmplMembers::staticDef() {} +template inline void ExportClassTmplMembers::staticInlineDef() {} +template void ExportClassTmplMembers::staticInlineDecl() {} +template void ExportClassTmplMembers::protectedDef() {} +template void ExportClassTmplMembers::privateDef() {} + +template struct ExportClassTmplMembers; + + +// Redeclarations cannot add dllexport. +template +struct CTMR /*ClassTmplMemberRedecl*/ { + void normalDef(); // expected-note{{previous declaration is here}} + void normalInlineDef(); // expected-note{{previous declaration is here}} + inline void normalInlineDecl(); // expected-note{{previous declaration is here}} + virtual void virtualDef(); // expected-note{{previous declaration is here}} + virtual void virtualInlineDef(); // expected-note{{previous declaration is here}} + virtual inline void virtualInlineDecl(); // expected-note{{previous declaration is here}} + static void staticDef(); // expected-note{{previous declaration is here}} + static void staticInlineDef(); // expected-note{{previous declaration is here}} + static inline void staticInlineDecl(); // expected-note{{previous declaration is here}} +}; + +template __declspec(dllexport) void CTMR::normalDef() {} // expected-error{{redeclaration of 'CTMR::normalDef' cannot add 'dllexport' attribute}} +template __declspec(dllexport) inline void CTMR::normalInlineDef() {} // expected-error{{redeclaration of 'CTMR::normalInlineDef' cannot add 'dllexport' attribute}} +template __declspec(dllexport) void CTMR::normalInlineDecl() {} // expected-error{{redeclaration of 'CTMR::normalInlineDecl' cannot add 'dllexport' attribute}} +template __declspec(dllexport) void CTMR::virtualDef() {} // expected-error{{redeclaration of 'CTMR::virtualDef' cannot add 'dllexport' attribute}} +template __declspec(dllexport) inline void CTMR::virtualInlineDef() {} // expected-error{{redeclaration of 'CTMR::virtualInlineDef' cannot add 'dllexport' attribute}} +template __declspec(dllexport) void CTMR::virtualInlineDecl() {} // expected-error{{redeclaration of 'CTMR::virtualInlineDecl' cannot add 'dllexport' attribute}} +template __declspec(dllexport) void CTMR::staticDef() {} // expected-error{{redeclaration of 'CTMR::staticDef' cannot add 'dllexport' attribute}} +template __declspec(dllexport) inline void CTMR::staticInlineDef() {} // expected-error{{redeclaration of 'CTMR::staticInlineDef' cannot add 'dllexport' attribute}} +template __declspec(dllexport) void CTMR::staticInlineDecl() {} // expected-error{{redeclaration of 'CTMR::staticInlineDecl' cannot add 'dllexport' attribute}} + + + +//===----------------------------------------------------------------------===// +// Class template member templates +//===----------------------------------------------------------------------===// + +template +struct ExportClsTmplMemTmpl { + template __declspec(dllexport) void normalDecl(); + template __declspec(dllexport) void normalDef(); + template __declspec(dllexport) void normalInclass() {} + template __declspec(dllexport) void normalInlineDef(); + template __declspec(dllexport) inline void normalInlineDecl(); + template __declspec(dllexport) static void staticDecl(); + template __declspec(dllexport) static void staticDef(); + template __declspec(dllexport) static void staticInclass() {} + template __declspec(dllexport) static void staticInlineDef(); + template __declspec(dllexport) static inline void staticInlineDecl(); +}; + +template template void ExportClsTmplMemTmpl::normalDef() {} +template template inline void ExportClsTmplMemTmpl::normalInlineDef() {} +template template void ExportClsTmplMemTmpl::normalInlineDecl() {} +template template void ExportClsTmplMemTmpl::staticDef() {} +template template inline void ExportClsTmplMemTmpl::staticInlineDef() {} +template template void ExportClsTmplMemTmpl::staticInlineDecl() {} + + +// Redeclarations cannot add dllexport. +template +struct CTMTR /*ClassTmplMemberTmplRedecl*/ { + template void normalDef(); // expected-note{{previous declaration is here}} + template void normalInlineDef(); // expected-note{{previous declaration is here}} + template inline void normalInlineDecl(); // expected-note{{previous declaration is here}} + template static void staticDef(); // expected-note{{previous declaration is here}} + template static void staticInlineDef(); // expected-note{{previous declaration is here}} + template static inline void staticInlineDecl(); // expected-note{{previous declaration is here}} +}; + +template template __declspec(dllexport) void CTMTR::normalDef() {} // expected-error{{redeclaration of 'CTMTR::normalDef' cannot add 'dllexport' attribute}} +template template __declspec(dllexport) inline void CTMTR::normalInlineDef() {} // expected-error{{redeclaration of 'CTMTR::normalInlineDef' cannot add 'dllexport' attribute}} +template template __declspec(dllexport) void CTMTR::normalInlineDecl() {} // expected-error{{redeclaration of 'CTMTR::normalInlineDecl' cannot add 'dllexport' attribute}} +template template __declspec(dllexport) void CTMTR::staticDef() {} // expected-error{{redeclaration of 'CTMTR::staticDef' cannot add 'dllexport' attribute}} +template template __declspec(dllexport) inline void CTMTR::staticInlineDef() {} // expected-error{{redeclaration of 'CTMTR::staticInlineDef' cannot add 'dllexport' attribute}} +template template __declspec(dllexport) void CTMTR::staticInlineDecl() {} // expected-error{{redeclaration of 'CTMTR::staticInlineDecl' cannot add 'dllexport' attribute}} diff --git a/test/SemaCXX/dllimport.cpp b/test/SemaCXX/dllimport.cpp index 954b543f3f..41f8e3c8f7 100644 --- a/test/SemaCXX/dllimport.cpp +++ b/test/SemaCXX/dllimport.cpp @@ -353,3 +353,394 @@ template __declspec(dllimport) void inlineFuncTmpl(); template<> __declspec(dllimport) void funcTmpl(); template<> __declspec(dllimport) void funcTmpl() {} // expected-error{{dllimport cannot be applied to non-inline function definition}} template<> __declspec(dllimport) inline void funcTmpl() {} + + + +//===----------------------------------------------------------------------===// +// Class members +//===----------------------------------------------------------------------===// + +// Import individual members of a class. +struct ImportMembers { + struct Nested { + __declspec(dllimport) void normalDecl(); + __declspec(dllimport) void normalDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} + }; + + __declspec(dllimport) void normalDecl(); + __declspec(dllimport) void normalDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} + __declspec(dllimport) void normalInclass() {} + __declspec(dllimport) void normalInlineDef(); + __declspec(dllimport) inline void normalInlineDecl(); + __declspec(dllimport) virtual void virtualDecl(); + __declspec(dllimport) virtual void virtualDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} + __declspec(dllimport) virtual void virtualInclass() {} + __declspec(dllimport) virtual void virtualInlineDef(); + __declspec(dllimport) virtual inline void virtualInlineDecl(); + __declspec(dllimport) static void staticDecl(); + __declspec(dllimport) static void staticDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} + __declspec(dllimport) static void staticInclass() {} + __declspec(dllimport) static void staticInlineDef(); + __declspec(dllimport) static inline void staticInlineDecl(); + +protected: + __declspec(dllimport) void protectedDecl(); +private: + __declspec(dllimport) void privateDecl(); +}; + + void ImportMembers::Nested::normalDef() {} // expected-warning{{'ImportMembers::Nested::normalDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} + void ImportMembers::normalDef() {} // expected-warning{{'ImportMembers::normalDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} +inline void ImportMembers::normalInlineDef() {} + void ImportMembers::normalInlineDecl() {} + void ImportMembers::virtualDef() {} // expected-warning{{'ImportMembers::virtualDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} +inline void ImportMembers::virtualInlineDef() {} + void ImportMembers::virtualInlineDecl() {} + void ImportMembers::staticDef() {} // expected-warning{{'ImportMembers::staticDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} +inline void ImportMembers::staticInlineDef() {} + void ImportMembers::staticInlineDecl() {} + + +// Import on member definitions. +struct ImportMemberDefs { + __declspec(dllimport) void normalDef(); + __declspec(dllimport) void normalInlineDef(); + __declspec(dllimport) inline void normalInlineDecl(); + __declspec(dllimport) virtual void virtualDef(); + __declspec(dllimport) virtual void virtualInlineDef(); + __declspec(dllimport) virtual inline void virtualInlineDecl(); + __declspec(dllimport) static void staticDef(); + __declspec(dllimport) static void staticInlineDef(); + __declspec(dllimport) static inline void staticInlineDecl(); +}; + +__declspec(dllimport) void ImportMemberDefs::normalDef() {} // expected-error{{dllimport cannot be applied to non-inline function definition}} +__declspec(dllimport) inline void ImportMemberDefs::normalInlineDef() {} +__declspec(dllimport) void ImportMemberDefs::normalInlineDecl() {} +__declspec(dllimport) void ImportMemberDefs::virtualDef() {} // expected-error{{dllimport cannot be applied to non-inline function definition}} +__declspec(dllimport) inline void ImportMemberDefs::virtualInlineDef() {} +__declspec(dllimport) void ImportMemberDefs::virtualInlineDecl() {} +__declspec(dllimport) void ImportMemberDefs::staticDef() {} // expected-error{{dllimport cannot be applied to non-inline function definition}} +__declspec(dllimport) inline void ImportMemberDefs::staticInlineDef() {} +__declspec(dllimport) void ImportMemberDefs::staticInlineDecl() {} + + +// Import special member functions. +struct ImportSpecials { + __declspec(dllimport) ImportSpecials(); + __declspec(dllimport) ~ImportSpecials(); + __declspec(dllimport) ImportSpecials(const ImportSpecials&); + __declspec(dllimport) ImportSpecials& operator=(const ImportSpecials&); + __declspec(dllimport) ImportSpecials(ImportSpecials&&); + __declspec(dllimport) ImportSpecials& operator=(ImportSpecials&&); +}; + + +// Import allocation functions. +struct ImportAlloc { + __declspec(dllimport) void* operator new(__SIZE_TYPE__); + __declspec(dllimport) void* operator new[](__SIZE_TYPE__); + __declspec(dllimport) void operator delete(void*); + __declspec(dllimport) void operator delete[](void*); +}; + + +// Import defaulted member functions. +struct ImportDefaulted { + __declspec(dllimport) ImportDefaulted() = default; + __declspec(dllimport) ~ImportDefaulted() = default; + __declspec(dllimport) ImportDefaulted(const ImportDefaulted&) = default; + __declspec(dllimport) ImportDefaulted& operator=(const ImportDefaulted&) = default; + __declspec(dllimport) ImportDefaulted(ImportDefaulted&&) = default; + __declspec(dllimport) ImportDefaulted& operator=(ImportDefaulted&&) = default; +}; + + +// Import defaulted member function definitions. +struct ImportDefaultedDefs { + __declspec(dllimport) ImportDefaultedDefs(); + __declspec(dllimport) ~ImportDefaultedDefs(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} + + __declspec(dllimport) inline ImportDefaultedDefs(const ImportDefaultedDefs&); + __declspec(dllimport) ImportDefaultedDefs& operator=(const ImportDefaultedDefs&); + + __declspec(dllimport) ImportDefaultedDefs(ImportDefaultedDefs&&); + __declspec(dllimport) ImportDefaultedDefs& operator=(ImportDefaultedDefs&&); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} +}; + +// Not allowed on definitions. +__declspec(dllimport) ImportDefaultedDefs::ImportDefaultedDefs() = default; // expected-error{{dllimport cannot be applied to non-inline function definition}} + +// dllimport cannot be dropped. +ImportDefaultedDefs::~ImportDefaultedDefs() = default; // expected-warning{{'ImportDefaultedDefs::~ImportDefaultedDefs' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} + +// Import inline declaration and definition. +__declspec(dllimport) ImportDefaultedDefs::ImportDefaultedDefs(const ImportDefaultedDefs&) = default; +inline ImportDefaultedDefs& ImportDefaultedDefs::operator=(const ImportDefaultedDefs&) = default; + +__declspec(dllimport) ImportDefaultedDefs::ImportDefaultedDefs(ImportDefaultedDefs&&) = default; // expected-error{{dllimport cannot be applied to non-inline function definition}} +ImportDefaultedDefs& ImportDefaultedDefs::operator=(ImportDefaultedDefs&&) = default; // expected-warning{{'ImportDefaultedDefs::operator=' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} + + +// Redeclarations cannot add dllimport. +struct MemberRedecl { + void normalDef(); // expected-note{{previous declaration is here}} + void normalInlineDef(); // expected-note{{previous declaration is here}} + inline void normalInlineDecl(); // expected-note{{previous declaration is here}} + virtual void virtualDef(); // expected-note{{previous declaration is here}} + virtual void virtualInlineDef(); // expected-note{{previous declaration is here}} + virtual inline void virtualInlineDecl(); // expected-note{{previous declaration is here}} + static void staticDef(); // expected-note{{previous declaration is here}} + static void staticInlineDef(); // expected-note{{previous declaration is here}} + static inline void staticInlineDecl(); // expected-note{{previous declaration is here}} +}; + +__declspec(dllimport) void MemberRedecl::normalDef() {} // expected-error{{redeclaration of 'MemberRedecl::normalDef' cannot add 'dllimport' attribute}} + // expected-error@-1{{dllimport cannot be applied to non-inline function definition}} +__declspec(dllimport) inline void MemberRedecl::normalInlineDef() {} // expected-error{{redeclaration of 'MemberRedecl::normalInlineDef' cannot add 'dllimport' attribute}} +__declspec(dllimport) void MemberRedecl::normalInlineDecl() {} // expected-error{{redeclaration of 'MemberRedecl::normalInlineDecl' cannot add 'dllimport' attribute}} +__declspec(dllimport) void MemberRedecl::virtualDef() {} // expected-error{{redeclaration of 'MemberRedecl::virtualDef' cannot add 'dllimport' attribute}} + // expected-error@-1{{dllimport cannot be applied to non-inline function definition}} +__declspec(dllimport) inline void MemberRedecl::virtualInlineDef() {} // expected-error{{redeclaration of 'MemberRedecl::virtualInlineDef' cannot add 'dllimport' attribute}} +__declspec(dllimport) void MemberRedecl::virtualInlineDecl() {} // expected-error{{redeclaration of 'MemberRedecl::virtualInlineDecl' cannot add 'dllimport' attribute}} +__declspec(dllimport) void MemberRedecl::staticDef() {} // expected-error{{redeclaration of 'MemberRedecl::staticDef' cannot add 'dllimport' attribute}} + // expected-error@-1{{dllimport cannot be applied to non-inline function definition}} +__declspec(dllimport) inline void MemberRedecl::staticInlineDef() {} // expected-error{{redeclaration of 'MemberRedecl::staticInlineDef' cannot add 'dllimport' attribute}} +__declspec(dllimport) void MemberRedecl::staticInlineDecl() {} // expected-error{{redeclaration of 'MemberRedecl::staticInlineDecl' cannot add 'dllimport' attribute}} + + + +//===----------------------------------------------------------------------===// +// Class member templates +//===----------------------------------------------------------------------===// + +struct ImportMemberTmpl { + template __declspec(dllimport) void normalDecl(); + template __declspec(dllimport) void normalDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} + template __declspec(dllimport) void normalInclass() {} + template __declspec(dllimport) void normalInlineDef(); + template __declspec(dllimport) inline void normalInlineDecl(); + template __declspec(dllimport) static void staticDecl(); + template __declspec(dllimport) static void staticDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} + template __declspec(dllimport) static void staticInclass() {} + template __declspec(dllimport) static void staticInlineDef(); + template __declspec(dllimport) static inline void staticInlineDecl(); +}; + +template void ImportMemberTmpl::normalDef() {} // expected-warning{{'ImportMemberTmpl::normalDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} +template inline void ImportMemberTmpl::normalInlineDef() {} +template void ImportMemberTmpl::normalInlineDecl() {} +template void ImportMemberTmpl::staticDef() {} // expected-warning{{'ImportMemberTmpl::staticDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} +template inline void ImportMemberTmpl::staticInlineDef() {} +template void ImportMemberTmpl::staticInlineDecl() {} + + +// Redeclarations cannot add dllimport. +struct MemTmplRedecl { + template void normalDef(); // expected-note{{previous declaration is here}} + template void normalInlineDef(); // expected-note{{previous declaration is here}} + template inline void normalInlineDecl(); // expected-note{{previous declaration is here}} + template static void staticDef(); // expected-note{{previous declaration is here}} + template static void staticInlineDef(); // expected-note{{previous declaration is here}} + template static inline void staticInlineDecl(); // expected-note{{previous declaration is here}} +}; + +template __declspec(dllimport) void MemTmplRedecl::normalDef() {} // expected-error{{redeclaration of 'MemTmplRedecl::normalDef' cannot add 'dllimport' attribute}} + // expected-error@-1{{dllimport cannot be applied to non-inline function definition}} +template __declspec(dllimport) inline void MemTmplRedecl::normalInlineDef() {} // expected-error{{redeclaration of 'MemTmplRedecl::normalInlineDef' cannot add 'dllimport' attribute}} +template __declspec(dllimport) void MemTmplRedecl::normalInlineDecl() {} // expected-error{{redeclaration of 'MemTmplRedecl::normalInlineDecl' cannot add 'dllimport' attribute}} +template __declspec(dllimport) void MemTmplRedecl::staticDef() {} // expected-error{{redeclaration of 'MemTmplRedecl::staticDef' cannot add 'dllimport' attribute}} + // expected-error@-1{{dllimport cannot be applied to non-inline function definition}} +template __declspec(dllimport) inline void MemTmplRedecl::staticInlineDef() {} // expected-error{{redeclaration of 'MemTmplRedecl::staticInlineDef' cannot add 'dllimport' attribute}} +template __declspec(dllimport) void MemTmplRedecl::staticInlineDecl() {} // expected-error{{redeclaration of 'MemTmplRedecl::staticInlineDecl' cannot add 'dllimport' attribute}} + + + +struct MemFunTmpl { + template void normalDef() {} + template __declspec(dllimport) void importedNormal() {} + template static void staticDef() {} + template __declspec(dllimport) static void importedStatic() {} +}; + +// Import implicit instantiation of an imported member function template. +void useMemFunTmpl() { + MemFunTmpl().importedNormal(); + MemFunTmpl().importedStatic(); +} + +// Import explicit instantiation declaration of an imported member function +// template. +extern template void MemFunTmpl::importedNormal(); +extern template void MemFunTmpl::importedStatic(); + +// Import explicit instantiation definition of an imported member function +// template. +// NB: MSVC fails this instantiation without explicit dllimport. +template void MemFunTmpl::importedNormal(); +template void MemFunTmpl::importedStatic(); + +// Import specialization of an imported member function template. +template<> __declspec(dllimport) void MemFunTmpl::importedNormal(); +template<> __declspec(dllimport) void MemFunTmpl::importedNormal() {} // error on mingw +template<> __declspec(dllimport) inline void MemFunTmpl::importedNormal() {} +#ifndef MSABI +// expected-error@-3{{dllimport cannot be applied to non-inline function definition}} +#endif + +template<> __declspec(dllimport) void MemFunTmpl::importedStatic(); +template<> __declspec(dllimport) void MemFunTmpl::importedStatic() {} // error on mingw +template<> __declspec(dllimport) inline void MemFunTmpl::importedStatic() {} +#ifndef MSABI +// expected-error@-3{{dllimport cannot be applied to non-inline function definition}} +#endif + +// Not importing specialization of an imported member function template without +// explicit dllimport. +template<> void MemFunTmpl::importedNormal() {} +template<> void MemFunTmpl::importedStatic() {} + + +// Import explicit instantiation declaration of a non-imported member function +// template. +extern template __declspec(dllimport) void MemFunTmpl::normalDef(); +extern template __declspec(dllimport) void MemFunTmpl::staticDef(); + +// Import explicit instantiation definition of a non-imported member function +// template. +template __declspec(dllimport) void MemFunTmpl::normalDef(); +template __declspec(dllimport) void MemFunTmpl::staticDef(); + +// Import specialization of a non-imported member function template. +template<> __declspec(dllimport) void MemFunTmpl::normalDef(); +template<> __declspec(dllimport) void MemFunTmpl::normalDef() {} // error on mingw +template<> __declspec(dllimport) inline void MemFunTmpl::normalDef() {} +#ifndef MSABI +// expected-error@-3{{dllimport cannot be applied to non-inline function definition}} +#endif + +template<> __declspec(dllimport) void MemFunTmpl::staticDef(); +template<> __declspec(dllimport) void MemFunTmpl::staticDef() {} // error on mingw +template<> __declspec(dllimport) inline void MemFunTmpl::staticDef() {} +#ifndef MSABI +// expected-error@-3{{dllimport cannot be applied to non-inline function definition}} +#endif + + + +//===----------------------------------------------------------------------===// +// Class template members +//===----------------------------------------------------------------------===// + +// Import individual members of a class template. +template +struct ImportClassTmplMembers { + __declspec(dllimport) void normalDecl(); + __declspec(dllimport) void normalDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} + __declspec(dllimport) void normalInclass() {} + __declspec(dllimport) void normalInlineDef(); + __declspec(dllimport) inline void normalInlineDecl(); + __declspec(dllimport) virtual void virtualDecl(); + __declspec(dllimport) virtual void virtualDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} + __declspec(dllimport) virtual void virtualInclass() {} + __declspec(dllimport) virtual void virtualInlineDef(); + __declspec(dllimport) virtual inline void virtualInlineDecl(); + __declspec(dllimport) static void staticDecl(); + __declspec(dllimport) static void staticDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} + __declspec(dllimport) static void staticInclass() {} + __declspec(dllimport) static void staticInlineDef(); + __declspec(dllimport) static inline void staticInlineDecl(); + +protected: + __declspec(dllimport) void protectedDecl(); +private: + __declspec(dllimport) void privateDecl(); +}; + +// NB: MSVC is inconsistent here and disallows *InlineDef on class templates, +// but allows it on classes. We allow both. +template void ImportClassTmplMembers::normalDef() {} // expected-warning{{'ImportClassTmplMembers::normalDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} +template inline void ImportClassTmplMembers::normalInlineDef() {} +template void ImportClassTmplMembers::normalInlineDecl() {} +template void ImportClassTmplMembers::virtualDef() {} // expected-warning{{'ImportClassTmplMembers::virtualDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} +template inline void ImportClassTmplMembers::virtualInlineDef() {} +template void ImportClassTmplMembers::virtualInlineDecl() {} +template void ImportClassTmplMembers::staticDef() {} // expected-warning{{'ImportClassTmplMembers::staticDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} +template inline void ImportClassTmplMembers::staticInlineDef() {} +template void ImportClassTmplMembers::staticInlineDecl() {} + + +// Redeclarations cannot add dllimport. +template +struct CTMR /*ClassTmplMemberRedecl*/ { + void normalDef(); // expected-note{{previous declaration is here}} + void normalInlineDef(); // expected-note{{previous declaration is here}} + inline void normalInlineDecl(); // expected-note{{previous declaration is here}} + virtual void virtualDef(); // expected-note{{previous declaration is here}} + virtual void virtualInlineDef(); // expected-note{{previous declaration is here}} + virtual inline void virtualInlineDecl(); // expected-note{{previous declaration is here}} + static void staticDef(); // expected-note{{previous declaration is here}} + static void staticInlineDef(); // expected-note{{previous declaration is here}} + static inline void staticInlineDecl(); // expected-note{{previous declaration is here}} +}; + +template __declspec(dllimport) void CTMR::normalDef() {} // expected-error{{redeclaration of 'CTMR::normalDef' cannot add 'dllimport' attribute}} + // expected-error@-1{{dllimport cannot be applied to non-inline function definition}} +template __declspec(dllimport) inline void CTMR::normalInlineDef() {} // expected-error{{redeclaration of 'CTMR::normalInlineDef' cannot add 'dllimport' attribute}} +template __declspec(dllimport) void CTMR::normalInlineDecl() {} // expected-error{{redeclaration of 'CTMR::normalInlineDecl' cannot add 'dllimport' attribute}} +template __declspec(dllimport) void CTMR::virtualDef() {} // expected-error{{redeclaration of 'CTMR::virtualDef' cannot add 'dllimport' attribute}} + // expected-error@-1{{dllimport cannot be applied to non-inline function definition}} +template __declspec(dllimport) inline void CTMR::virtualInlineDef() {} // expected-error{{redeclaration of 'CTMR::virtualInlineDef' cannot add 'dllimport' attribute}} +template __declspec(dllimport) void CTMR::virtualInlineDecl() {} // expected-error{{redeclaration of 'CTMR::virtualInlineDecl' cannot add 'dllimport' attribute}} +template __declspec(dllimport) void CTMR::staticDef() {} // expected-error{{redeclaration of 'CTMR::staticDef' cannot add 'dllimport' attribute}} + // expected-error@-1{{dllimport cannot be applied to non-inline function definition}} +template __declspec(dllimport) inline void CTMR::staticInlineDef() {} // expected-error{{redeclaration of 'CTMR::staticInlineDef' cannot add 'dllimport' attribute}} +template __declspec(dllimport) void CTMR::staticInlineDecl() {} // expected-error{{redeclaration of 'CTMR::staticInlineDecl' cannot add 'dllimport' attribute}} + + + +//===----------------------------------------------------------------------===// +// Class template member templates +//===----------------------------------------------------------------------===// + +template +struct ImportClsTmplMemTmpl { + template __declspec(dllimport) void normalDecl(); + template __declspec(dllimport) void normalDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} + template __declspec(dllimport) void normalInclass() {} + template __declspec(dllimport) void normalInlineDef(); + template __declspec(dllimport) inline void normalInlineDecl(); + template __declspec(dllimport) static void staticDecl(); + template __declspec(dllimport) static void staticDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} + template __declspec(dllimport) static void staticInclass() {} + template __declspec(dllimport) static void staticInlineDef(); + template __declspec(dllimport) static inline void staticInlineDecl(); +}; + +template template void ImportClsTmplMemTmpl::normalDef() {} // expected-warning{{'ImportClsTmplMemTmpl::normalDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} +template template inline void ImportClsTmplMemTmpl::normalInlineDef() {} +template template void ImportClsTmplMemTmpl::normalInlineDecl() {} +template template void ImportClsTmplMemTmpl::staticDef() {} // expected-warning{{'ImportClsTmplMemTmpl::staticDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} +template template inline void ImportClsTmplMemTmpl::staticInlineDef() {} +template template void ImportClsTmplMemTmpl::staticInlineDecl() {} + + +// Redeclarations cannot add dllimport. +template +struct CTMTR /*ClassTmplMemberTmplRedecl*/ { + template void normalDef(); // expected-note{{previous declaration is here}} + template void normalInlineDef(); // expected-note{{previous declaration is here}} + template inline void normalInlineDecl(); // expected-note{{previous declaration is here}} + template static void staticDef(); // expected-note{{previous declaration is here}} + template static void staticInlineDef(); // expected-note{{previous declaration is here}} + template static inline void staticInlineDecl(); // expected-note{{previous declaration is here}} +}; + +template template __declspec(dllimport) void CTMTR::normalDef() {} // expected-error{{redeclaration of 'CTMTR::normalDef' cannot add 'dllimport' attribute}} + // expected-error@-1{{dllimport cannot be applied to non-inline function definition}} +template template __declspec(dllimport) inline void CTMTR::normalInlineDef() {} // expected-error{{redeclaration of 'CTMTR::normalInlineDef' cannot add 'dllimport' attribute}} +template template __declspec(dllimport) void CTMTR::normalInlineDecl() {} // expected-error{{redeclaration of 'CTMTR::normalInlineDecl' cannot add 'dllimport' attribute}} +template template __declspec(dllimport) void CTMTR::staticDef() {} // expected-error{{redeclaration of 'CTMTR::staticDef' cannot add 'dllimport' attribute}} + // expected-error@-1{{dllimport cannot be applied to non-inline function definition}} +template template __declspec(dllimport) inline void CTMTR::staticInlineDef() {} // expected-error{{redeclaration of 'CTMTR::staticInlineDef' cannot add 'dllimport' attribute}} +template template __declspec(dllimport) void CTMTR::staticInlineDecl() {} // expected-error{{redeclaration of 'CTMTR::staticInlineDecl' cannot add 'dllimport' attribute}}