You can use an alias template to get an unqualified type name when all you have is a qualified type name. The following should work
template<typename T> using alias = T;
ptr->~alias<std::remove_reference<decltype(*ptr)>::type>();
Note that if the remove_reference
thing worked, it would still be dangerous, because by the qualified type name, you would inhibit an virtual destructor call. By using the alias template, virtual destructors still work.
Note that GCC4.8 appears to accept
ptr->std::remove_reference<decltype(*ptr)>::type::~type();
Clang rejects this. I have long given up trying to understand how destructor name lookup works (if you look into the clang source, you will note that the clang developers also do not follow the spec, because they say that it makes no sense here). There exist DRs that cover destructor call syntax and how they are messed up. Therefor, I would recommend not using any complicated syntax here.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…