Fix memory leak complicated non-type template arguments.

This commit is contained in:
Richard Smith 2020-12-18 13:25:18 -08:00
parent 72d8f79f0c
commit ed13d8c667
2 changed files with 3 additions and 2 deletions

View file

@ -2818,8 +2818,8 @@ public:
/// for destruction.
template <typename T> void addDestruction(T *Ptr) const {
if (!std::is_trivially_destructible<T>::value) {
auto DestroyPtr = [](void *V) { static_cast<T *>(V)->~T(); };
AddDeallocation(DestroyPtr, Ptr);
auto DestroyPtr = [](void *V) { ((T*)V)->~T(); };
AddDeallocation(DestroyPtr, (void*)Ptr);
}
}

View file

@ -137,6 +137,7 @@ TemplateArgument::TemplateArgument(const ASTContext &Ctx, QualType Type,
else {
Value.Kind = UncommonValue;
Value.Value = new (Ctx) APValue(V);
Ctx.addDestruction(Value.Value);
Value.Type = Type.getAsOpaquePtr();
}
}