Fix memory leak complicated non-type template arguments.
authorRichard Smith <richard@metafoo.co.uk>
Fri, 18 Dec 2020 21:25:18 +0000 (13:25 -0800)
committerRichard Smith <richard@metafoo.co.uk>
Fri, 18 Dec 2020 21:42:24 +0000 (13:42 -0800)
clang/include/clang/AST/ASTContext.h
clang/lib/AST/TemplateBase.cpp

index 0c5d82b..a9bfdb4 100644 (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);
     }
   }
 
index 0029c90..a746db3 100644 (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();
   }
 }