[clang] [clang] Fix manual memory management with SmallVector in ConceptRef (PR #147231)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 6 20:03:48 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Bogdan Vetrenko (bv2k4)
<details>
<summary>Changes</summary>
This change replaces manual `new[]`/`delete[]` with `llvm::SmallVector` for `TemplateArgumentLocInfo` in `createTrivialConceptReference`.
---
Full diff: https://github.com/llvm/llvm-project/pull/147231.diff
1 Files Affected:
- (modified) clang/lib/AST/TypeLoc.cpp (+3-3)
``````````diff
diff --git a/clang/lib/AST/TypeLoc.cpp b/clang/lib/AST/TypeLoc.cpp
index 1bdb86ad445a4..5c45c596538f8 100644
--- a/clang/lib/AST/TypeLoc.cpp
+++ b/clang/lib/AST/TypeLoc.cpp
@@ -22,6 +22,7 @@
#include "clang/AST/TypeLocVisitor.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/Specifiers.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include <algorithm>
@@ -652,9 +653,9 @@ static ConceptReference *createTrivialConceptReference(ASTContext &Context,
DeclarationNameInfo(AT->getTypeConstraintConcept()->getDeclName(), Loc,
AT->getTypeConstraintConcept()->getDeclName());
unsigned size = AT->getTypeConstraintArguments().size();
- TemplateArgumentLocInfo *TALI = new TemplateArgumentLocInfo[size];
+ llvm::SmallVector<TemplateArgumentLocInfo, 8> TALI(size);
TemplateSpecializationTypeLoc::initializeArgLocs(
- Context, AT->getTypeConstraintArguments(), TALI, Loc);
+ Context, AT->getTypeConstraintArguments(), TALI.data(), Loc);
TemplateArgumentListInfo TAListI;
for (unsigned i = 0; i < size; ++i) {
TAListI.addArgument(
@@ -666,7 +667,6 @@ static ConceptReference *createTrivialConceptReference(ASTContext &Context,
Context, NestedNameSpecifierLoc{}, Loc, DNI, nullptr,
AT->getTypeConstraintConcept(),
ASTTemplateArgumentListInfo::Create(Context, TAListI));
- delete[] TALI;
return ConceptRef;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/147231
More information about the cfe-commits
mailing list