diff options
author | Nico Rieck <nico.rieck@gmail.com> | 2014-05-29 16:50:20 +0000 |
---|---|---|
committer | Nico Rieck <nico.rieck@gmail.com> | 2014-05-29 16:50:20 +0000 |
commit | 078d2f89cd6adf8ed6e464c2432f9a55b2cb1534 (patch) | |
tree | 99bb73c120f6b1b7c0da18742c6c94922ba7b6a4 /clang/lib/Sema/SemaDecl.cpp | |
parent | a670c20894c6c8881a8be958a69aaa25e8df31e4 (diff) | |
download | llvm-078d2f89cd6adf8ed6e464c2432f9a55b2cb1534.zip llvm-078d2f89cd6adf8ed6e464c2432f9a55b2cb1534.tar.gz llvm-078d2f89cd6adf8ed6e464c2432f9a55b2cb1534.tar.bz2 |
Sema: Check dll attributes on static data members
Redeclarations cannot add a dll attribute and static data members cannot
be defined.
llvm-svn: 209825
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 9614d0d..075b399 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -4907,10 +4907,15 @@ static void checkDLLAttributeRedeclaration(Sema &S, NamedDecl *OldDecl, // A redeclaration is not allowed to drop a dllimport attribute, the only // exception being inline function definitions. // NB: MSVC converts such a declaration to dllexport. - bool IsInline = - isa<FunctionDecl>(NewDecl) && cast<FunctionDecl>(NewDecl)->isInlined(); - - if (OldImportAttr && !HasNewAttr && !IsInline) { + bool IsInline = false, IsStaticDataMember = false; + if (const auto *VD = dyn_cast<VarDecl>(NewDecl)) + // Ignore static data because out-of-line definitions are diagnosed + // separately. + IsStaticDataMember = VD->isStaticDataMember(); + else if (const auto *FD = dyn_cast<FunctionDecl>(NewDecl)) + IsInline = FD->isInlined(); + + if (OldImportAttr && !HasNewAttr && !IsInline && !IsStaticDataMember) { S.Diag(NewDecl->getLocation(), diag::warn_redeclaration_without_attribute_prev_attribute_ignored) << NewDecl << OldImportAttr; @@ -9052,6 +9057,17 @@ Sema::FinalizeDeclaration(Decl *ThisDecl) { checkAttributesAfterMerging(*this, *VD); + // Imported static data members cannot be defined out-of-line. + if (const DLLImportAttr *IA = VD->getAttr<DLLImportAttr>()) { + if (VD->isStaticDataMember() && VD->isOutOfLine() && + VD->isThisDeclarationADefinition()) { + Diag(VD->getLocation(), + diag::err_attribute_dllimport_static_field_definition); + Diag(IA->getLocation(), diag::note_attribute); + VD->setInvalidDecl(); + } + } + if (UsedAttr *Attr = VD->getAttr<UsedAttr>()) { if (!Attr->isInherited() && !VD->isThisDeclarationADefinition()) { Diag(Attr->getLocation(), diag::warn_attribute_ignored) << Attr; |