Skip to content

Commit 95862d0

Browse files
authored
[clang] Fix manual memory management with SmallVector in ConceptRef (#147231)
This change replaces manual `new[]`/`delete[]` with `llvm::SmallVector` for `TemplateArgumentLocInfo` in `createTrivialConceptReference`.
1 parent 3c86b74 commit 95862d0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

clang/lib/AST/TypeLoc.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "clang/AST/TypeLocVisitor.h"
2323
#include "clang/Basic/SourceLocation.h"
2424
#include "clang/Basic/Specifiers.h"
25+
#include "llvm/ADT/SmallVector.h"
2526
#include "llvm/Support/ErrorHandling.h"
2627
#include "llvm/Support/MathExtras.h"
2728
#include <algorithm>
@@ -652,9 +653,9 @@ static ConceptReference *createTrivialConceptReference(ASTContext &Context,
652653
DeclarationNameInfo(AT->getTypeConstraintConcept()->getDeclName(), Loc,
653654
AT->getTypeConstraintConcept()->getDeclName());
654655
unsigned size = AT->getTypeConstraintArguments().size();
655-
TemplateArgumentLocInfo *TALI = new TemplateArgumentLocInfo[size];
656+
llvm::SmallVector<TemplateArgumentLocInfo, 8> TALI(size);
656657
TemplateSpecializationTypeLoc::initializeArgLocs(
657-
Context, AT->getTypeConstraintArguments(), TALI, Loc);
658+
Context, AT->getTypeConstraintArguments(), TALI.data(), Loc);
658659
TemplateArgumentListInfo TAListI;
659660
for (unsigned i = 0; i < size; ++i) {
660661
TAListI.addArgument(
@@ -666,7 +667,6 @@ static ConceptReference *createTrivialConceptReference(ASTContext &Context,
666667
Context, NestedNameSpecifierLoc{}, Loc, DNI, nullptr,
667668
AT->getTypeConstraintConcept(),
668669
ASTTemplateArgumentListInfo::Create(Context, TAListI));
669-
delete[] TALI;
670670
return ConceptRef;
671671
}
672672

0 commit comments

Comments
 (0)