Skip to content

Commit 6991fe6

Browse files
committed
fixup: simplify dependent type processing code
1 parent a901d4a commit 6991fe6

File tree

2 files changed

+6
-20
lines changed

2 files changed

+6
-20
lines changed

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,15 +1849,10 @@ bool Sema::CheckSpanLikeType(const AttributeCommonInfo &CI,
18491849
Diag(CI.getLoc(), diag::warn_attribute_return_span_only) << CI;
18501850
return Diag(CI.getLoc(), NoteDiagID);
18511851
};
1852-
if (!Ty->isDependentType()) {
1853-
// If the type is a class template specialization, it may not be
1854-
// instantiated at this stage. We must force it to be complete to examine
1855-
// its fields.
1856-
// The returned value is discarded since the code below emits a warning
1857-
// if the type keeps being incomplete.
1858-
(void)isCompleteType(CI.getLoc(), Ty);
1859-
}
1860-
if (Ty->isIncompleteType())
1852+
if (Ty->isDependentType())
1853+
return false;
1854+
// isCompleteType is used to force template class instantiation.
1855+
if (!isCompleteType(CI.getLoc(), Ty))
18611856
return emitWarning(diag::note_returned_incomplete_type);
18621857
const RecordDecl *RD = Ty->getAsRecordDecl();
18631858
if (!RD || RD->isUnion())
@@ -1899,11 +1894,8 @@ bool Sema::CheckSpanLikeType(const AttributeCommonInfo &CI,
18991894

19001895
static void handleMallocSpanAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
19011896
QualType ResultType = getFunctionOrMethodResultType(D);
1902-
if (ResultType->isDependentType() || !S.CheckSpanLikeType(AL, ResultType)) {
1903-
// If it's a dependent type, the attribute will be re-checked upon
1904-
// instantiation.
1897+
if (!S.CheckSpanLikeType(AL, ResultType))
19051898
D->addAttr(::new (S.Context) MallocSpanAttr(S.Context, AL));
1906-
}
19071899
}
19081900

19091901
static void handleCPUSpecificAttr(Sema &S, Decl *D, const ParsedAttr &AL) {

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -800,14 +800,8 @@ static void instantiateDependentMallocSpanAttr(Sema &S,
800800
const MallocSpanAttr *Attr,
801801
Decl *New) {
802802
QualType RT = getFunctionOrMethodResultType(New);
803-
if (RT->isDependentType()) {
804-
// The type is still dependent.
805-
// Clone the attribute, it will be checked later.
803+
if (!S.CheckSpanLikeType(*Attr, RT))
806804
New->addAttr(Attr->clone(S.getASTContext()));
807-
} else if (!S.CheckSpanLikeType(*Attr, RT)) {
808-
// The conditions have been successfully validated.
809-
New->addAttr(Attr->clone(S.getASTContext()));
810-
}
811805
}
812806

813807
void Sema::InstantiateAttrsForDecl(

0 commit comments

Comments
 (0)