From adf7d0b22705211f5629ee7d003080a5216349c3 Mon Sep 17 00:00:00 2001
From: Axel Naumann <Axel.Naumann@cern.ch>
Date: Wed, 4 Dec 2013 12:59:56 +0100
Subject: [PATCH] Use TypeName::GetFullyQualifiedName; no dtor on const.

(cherry picked from commit 1489235e30f296607acabe8b2ffb2b6923639d3b)
---
 .../cling/lib/Interpreter/StoredValueRef.cpp       | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/interpreter/cling/lib/Interpreter/StoredValueRef.cpp b/interpreter/cling/lib/Interpreter/StoredValueRef.cpp
index 24977f99250..ac3b2e2ef46 100644
--- a/interpreter/cling/lib/Interpreter/StoredValueRef.cpp
+++ b/interpreter/cling/lib/Interpreter/StoredValueRef.cpp
@@ -7,11 +7,12 @@
 #include "cling/Interpreter/StoredValueRef.h"
 #include "cling/Interpreter/Interpreter.h"
 #include "cling/Interpreter/ValuePrinter.h"
+#include "cling/Utils/AST.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/ExecutionEngine/GenericValue.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclCXX.h"
-#include "llvm/ExecutionEngine/GenericValue.h"
 #include "clang/Frontend/CompilerInstance.h"
-#include "llvm/Support/raw_ostream.h"
 
 using namespace cling;
 using namespace clang;
@@ -57,8 +58,11 @@ void* StoredValueRef::StoredValue::GetDtorWrapperPtr(CXXRecordDecl* CXXRD) {
     return dtorWrapperPtr;
 
   std::string code("extern \"C\" void ");
-  std::string typeName = getClangType().getAsString();
-  code += funcname + "(void*obj){((" + typeName + "*)obj)->~" + typeName +"();}";
+  std::string typeName
+    = utils::TypeName::GetFullyQualifiedName(getClangType(),
+                                             CXXRD->getASTContext());
+  code += funcname + "(void* obj){((" + typeName + "*)obj)->~"
+    + typeName +"();}";
   m_Interp.declare(code);
   return m_Interp.getAddressOfGlobal(funcname.c_str());
 }
@@ -75,6 +79,8 @@ void StoredValueRef::StoredValue::Destruct() {
   //       `-ImplicitCastExpr 'struct XB *' <LValueToRValue>
   //         `-DeclRefExpr  'struct XB *' lvalue ParmVar 'obj' 'struct XB *'
 
+  if (getClangType.isConst())
+    return;
   const RecordType* RT = dyn_cast<RecordType>(getClangType());
   if (!RT)
     return;
-- 
GitLab