Skip to content

Commit 3db5c05

Browse files
authored
Add Variadic 'dropAttrs' (#78476)
As suggested in #78200 This adds a variadic 'dropAttrs', which drops all attributes of any of the types specified.
1 parent 0f67c7a commit 3db5c05

File tree

4 files changed

+8
-11
lines changed

4 files changed

+8
-11
lines changed

clang/include/clang/AST/DeclBase.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,17 +548,18 @@ class alignas(8) Decl {
548548
return hasAttrs() ? getAttrs().end() : nullptr;
549549
}
550550

551-
template <typename T>
552-
void dropAttr() {
551+
template <typename... Ts> void dropAttrs() {
553552
if (!HasAttrs) return;
554553

555554
AttrVec &Vec = getAttrs();
556-
llvm::erase_if(Vec, [](Attr *A) { return isa<T>(A); });
555+
llvm::erase_if(Vec, [](Attr *A) { return isa<Ts...>(A); });
557556

558557
if (Vec.empty())
559558
HasAttrs = false;
560559
}
561560

561+
template <typename T> void dropAttr() { dropAttrs<T>(); }
562+
562563
template <typename T>
563564
llvm::iterator_range<specific_attr_iterator<T>> specific_attrs() const {
564565
return llvm::make_range(specific_attr_begin<T>(), specific_attr_end<T>());

clang/lib/Sema/SemaDecl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7068,8 +7068,7 @@ static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND) {
70687068
if (WeakRefAttr *Attr = ND.getAttr<WeakRefAttr>()) {
70697069
if (ND.isExternallyVisible()) {
70707070
S.Diag(Attr->getLocation(), diag::err_attribute_weakref_not_static);
7071-
ND.dropAttr<WeakRefAttr>();
7072-
ND.dropAttr<AliasAttr>();
7071+
ND.dropAttrs<WeakRefAttr, AliasAttr>();
70737072
}
70747073
}
70757074

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6545,8 +6545,7 @@ void Sema::checkClassLevelDLLAttribute(CXXRecordDecl *Class) {
65456545
if ((Context.getTargetInfo().getCXXABI().isMicrosoft() ||
65466546
Context.getTargetInfo().getTriple().isPS()) &&
65476547
(!Class->isExternallyVisible() && Class->hasExternalFormalLinkage())) {
6548-
Class->dropAttr<DLLExportAttr>();
6549-
Class->dropAttr<DLLImportAttr>();
6548+
Class->dropAttrs<DLLExportAttr, DLLImportAttr>();
65506549
return;
65516550
}
65526551

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9229,10 +9229,8 @@ void Sema::CheckConceptRedefinition(ConceptDecl *NewDecl,
92299229
/// that has just been explicitly specialized.
92309230
static void StripImplicitInstantiation(NamedDecl *D, bool MinGW) {
92319231
if (MinGW || (isa<FunctionDecl>(D) &&
9232-
cast<FunctionDecl>(D)->isFunctionTemplateSpecialization())) {
9233-
D->dropAttr<DLLImportAttr>();
9234-
D->dropAttr<DLLExportAttr>();
9235-
}
9232+
cast<FunctionDecl>(D)->isFunctionTemplateSpecialization()))
9233+
D->dropAttrs<DLLImportAttr, DLLExportAttr>();
92369234

92379235
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
92389236
FD->setInlineSpecified(false);

0 commit comments

Comments
 (0)