diff options
author | Hans Wennborg <hans@hanshq.net> | 2014-06-04 00:18:41 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2014-06-04 00:18:41 +0000 |
commit | e9af3164237f16a35e6f57c06f09b20cb7b4b622 (patch) | |
tree | 4eb060352c9e8fea1fb072d2fda4b450ce15b3ac /clang/lib | |
parent | 547f536bcf6a29ffd63b5f921c5c15732e17dd19 (diff) | |
download | llvm-e9af3164237f16a35e6f57c06f09b20cb7b4b622.zip llvm-e9af3164237f16a35e6f57c06f09b20cb7b4b622.tar.gz llvm-e9af3164237f16a35e6f57c06f09b20cb7b4b622.tar.bz2 |
Downgrade "definition of dllimport static field" error to warning for class templates (PR19902)
This allows us to compile the following kind of code, which occurs in MSVC
headers:
template <typename> struct S {
__declspec(dllimport) static int x;
};
template <typename T> int S<T>::x;
The definition works similarly to a dllimport inline function definition and
gets available_externally linkage.
Differential Revision: http://reviews.llvm.org/D3998
llvm-svn: 210141
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 075b399..9bd51b9 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -9061,10 +9061,19 @@ Sema::FinalizeDeclaration(Decl *ThisDecl) { if (const DLLImportAttr *IA = VD->getAttr<DLLImportAttr>()) { if (VD->isStaticDataMember() && VD->isOutOfLine() && VD->isThisDeclarationADefinition()) { + // We allow definitions of dllimport class template static data members + // with a warning. + bool IsClassTemplateMember = + cast<CXXRecordDecl>(VD->getFirstDecl()->getDeclContext()) + ->getDescribedClassTemplate(); + Diag(VD->getLocation(), - diag::err_attribute_dllimport_static_field_definition); + IsClassTemplateMember + ? diag::warn_attribute_dllimport_static_field_definition + : diag::err_attribute_dllimport_static_field_definition); Diag(IA->getLocation(), diag::note_attribute); - VD->setInvalidDecl(); + if (!IsClassTemplateMember) + VD->setInvalidDecl(); } } |