diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/DeclBase.cpp | 30 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 2 |
2 files changed, 17 insertions, 15 deletions
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index c183e61df8..69724a3d5e 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -520,20 +520,6 @@ void Decl::dropAttrs() { getASTContext().eraseDeclAttrs(this); } -void Decl::dropWeakImportAttr() { - if (!HasAttrs) return; - AttrVec &Attrs = getASTContext().getDeclAttrs(this); - for (llvm::SmallVectorImpl<Attr*>::iterator A = Attrs.begin(); - A != Attrs.end(); ++A) { - if (isa<WeakImportAttr>(*A)) { - Attrs.erase(A); - break; - } - } - if (Attrs.empty()) - HasAttrs = false; -} - const AttrVec &Decl::getAttrs() const { assert(HasAttrs && "No attrs to get!"); return getASTContext().getDeclAttrs(this); @@ -585,6 +571,22 @@ Decl *Decl::castFromDeclContext (const DeclContext *D) { } } +template <typename T> +void Decl::dropAttr() { + if (!HasAttrs) return; + AttrVec &Attrs = getASTContext().getDeclAttrs(this); + for (unsigned i = 0, e = Attrs.size(); i != e; ++i) { + if (isa<T>(Attrs[i])) { + Attrs.erase(Attrs.begin() + i); + --i, --e; + } + } + if (Attrs.empty()) + HasAttrs = false; +} +// Force instantiation for WeakImportAttr which gets used. +template void Decl::dropAttr<WeakImportAttr>(); + DeclContext *Decl::castToDeclContext(const Decl *D) { Decl::Kind DK = D->getKind(); switch(DK) { diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 487390bc29..4a000e9fc2 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -2046,7 +2046,7 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) { Diag(New->getLocation(), diag::warn_weak_import) << New->getDeclName(); Diag(Old->getLocation(), diag::note_previous_definition); // Remove weak_import attribute on new declaration. - New->dropWeakImportAttr(); + New->dropAttr<WeakImportAttr>(); } // Merge the types. |