Fix mismatched memory allocation and deallocation. (#6923)

In NestedNameSpecifier.cpp, the Append function allocates data using
`new`:


e1bb926f63/tools/clang/lib/AST/NestedNameSpecifier.cpp (L449-L450)

However, if it deallocated using `free`:


e1bb926f63/tools/clang/lib/AST/NestedNameSpecifier.cpp (L514-L516)

This can cause problems. I'm changing the `free` to `delete`.
This commit is contained in:
Steven Perron 2024-09-19 15:10:56 -04:00 коммит произвёл GitHub
Родитель 9f298d6fa2
Коммит 26ea670d97
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 19 добавлений и 2 удалений

Просмотреть файл

@ -512,7 +512,7 @@ operator=(const NestedNameSpecifierLocBuilder &Other) {
// Free our storage, if we have any.
if (BufferCapacity) {
free(Buffer);
delete[] Buffer; // HLSL Change: Use overridable operator delete
BufferCapacity = 0;
}
@ -647,7 +647,7 @@ void NestedNameSpecifierLocBuilder::MakeTrivial(ASTContext &Context,
void NestedNameSpecifierLocBuilder::Adopt(NestedNameSpecifierLoc Other) {
if (BufferCapacity)
free(Buffer);
delete[] Buffer; // HLSL Change: Use overridable operator delete
if (!Other) {
Representation = nullptr;

Просмотреть файл

@ -0,0 +1,17 @@
// RUN: %dxc -T cs_6_0 -E main -HV 2021 -verify %s
// expected-no-diagnostics
template <typename T>
class C {
C cast();
};
template <class T>
C<T>
C<T>::cast() {
C result;
return result;
}
[numthreads(64, 1, 1)] void main() {}