Avoid nullptr dereferencing of 'Constraint'; NFC

Klocwork static code analysis exposed this bug:
Pointer 'Constraint' returned from call to function
'cast_or_null<clang::ConceptSpecializationExpr,clang::Expr>' may
be NULL and will be dereferenced in the statement following it

Replace 'cast_or_null' with 'cast' so that the latter can assert
when it encounters a NULL.

This also removes an 'assert' that is covered by the previous
call to 'cast<>'.
This commit is contained in:
Sindhu Chittireddy 2021-08-24 07:08:18 -04:00 committed by Aaron Ballman
parent ebf35370ff
commit 98339f14a0
1 changed files with 1 additions and 4 deletions

View File

@ -1062,11 +1062,8 @@ ReturnTypeRequirement(TemplateParameterList *TPL) :
assert(TPL->size() == 1);
const TypeConstraint *TC =
cast<TemplateTypeParmDecl>(TPL->getParam(0))->getTypeConstraint();
assert(TC &&
"TPL must have a template type parameter with a type constraint");
auto *Constraint =
cast_or_null<ConceptSpecializationExpr>(
TC->getImmediatelyDeclaredConstraint());
cast<ConceptSpecializationExpr>(TC->getImmediatelyDeclaredConstraint());
bool Dependent =
Constraint->getTemplateArgsAsWritten() &&
TemplateSpecializationType::anyInstantiationDependentTemplateArguments(