From 078d2f89cd6adf8ed6e464c2432f9a55b2cb1534 Mon Sep 17 00:00:00 2001 From: Nico Rieck Date: Thu, 29 May 2014 16:50:20 +0000 Subject: Sema: Check dll attributes on static data members Redeclarations cannot add a dll attribute and static data members cannot be defined. llvm-svn: 209825 --- clang/lib/Sema/SemaDecl.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'clang/lib/Sema/SemaDecl.cpp') 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(NewDecl) && cast(NewDecl)->isInlined(); - - if (OldImportAttr && !HasNewAttr && !IsInline) { + bool IsInline = false, IsStaticDataMember = false; + if (const auto *VD = dyn_cast(NewDecl)) + // Ignore static data because out-of-line definitions are diagnosed + // separately. + IsStaticDataMember = VD->isStaticDataMember(); + else if (const auto *FD = dyn_cast(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()) { + 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()) { if (!Attr->isInherited() && !VD->isThisDeclarationADefinition()) { Diag(Attr->getLocation(), diag::warn_attribute_ignored) << Attr; -- cgit v1.1