diff --git a/CodeGenerator.cpp b/CodeGenerator.cpp index 646ffc1..25fd60f 100644 --- a/CodeGenerator.cpp +++ b/CodeGenerator.cpp @@ -2111,6 +2111,14 @@ bool CodeGenerator::InsideDecltype() const } //----------------------------------------------------------------------------- +void CodeGenerator::InsertArg(const CXXPseudoDestructorExpr* stmt) +{ + InsertArg(stmt->getBase()); + + mOutputFormatHelper.Append(ArrowOrDot(stmt->isArrow()), "~", GetName(stmt->getDestroyedType())); +} +//----------------------------------------------------------------------------- + void CodeGenerator::InsertArg(const CXXMemberCallExpr* stmt) { CONDITIONAL_LAMBDA_SCOPE_HELPER(MemberCallExpr, not InsideDecltype()) diff --git a/CodeGeneratorTypes.h b/CodeGeneratorTypes.h index 2a2aa0f..91299e8 100644 --- a/CodeGeneratorTypes.h +++ b/CodeGeneratorTypes.h @@ -135,6 +135,7 @@ SUPPORTED_STMT(StmtExpr) SUPPORTED_STMT(SourceLocExpr) SUPPORTED_STMT(CXXParenListInitExpr) SUPPORTED_STMT(CppInsightsCommentStmt) +SUPPORTED_STMT(CXXPseudoDestructorExpr) #undef IGNORED_DECL #undef IGNORED_STMT diff --git a/tests/PlacemenNew2Test.cpp b/tests/PlacemenNew2Test.cpp new file mode 100644 index 0000000..90934bb --- /dev/null +++ b/tests/PlacemenNew2Test.cpp @@ -0,0 +1,36 @@ +#include + +namespace Test { + template + struct Apple + { + T x; + }; + + template + void destroy(T* ptr) { + ptr->T::~T(); + } +} + +namespace West +{ + int y; +} + +int main() +{ + char buffer[sizeof(Test::Apple)]; + + auto f = new (&buffer) Test::Apple; + + f->Test::Apple::~Apple(); + f->~Apple(); + + Test::destroy(f); + + int x; + Test::destroy(&x); + + Test::destroy(&West::y); +} diff --git a/tests/PlacemenNew2Test.expect b/tests/PlacemenNew2Test.expect new file mode 100644 index 0000000..fdfe2d9 --- /dev/null +++ b/tests/PlacemenNew2Test.expect @@ -0,0 +1,66 @@ +#include + +namespace Test +{ + template + struct Apple + { + T x; + }; + + /* First instantiated from: PlacemenNew2Test.cpp:23 */ + #ifdef INSIGHTS_USE_TEMPLATE + template<> + struct Apple + { + int x; + // inline Apple() noexcept = default; + }; + + #endif + template + void destroy(T * ptr) + { + ptr->~T(); + } + + /* First instantiated from: PlacemenNew2Test.cpp:30 */ + #ifdef INSIGHTS_USE_TEMPLATE + template<> + void destroy >(Apple * ptr) + { + ptr->~Apple(); + } + #endif + + + /* First instantiated from: PlacemenNew2Test.cpp:33 */ + #ifdef INSIGHTS_USE_TEMPLATE + template<> + void destroy(int * ptr) + { + ptr->~int(); + } + #endif + + +} + +namespace West +{ + int y; + +} + +int main() +{ + char buffer[4]; + Test::Apple * f = new (reinterpret_cast(&buffer))Test::Apple(); + f->~Apple(); + f->~Apple(); + Test::destroy(f); + int x; + Test::destroy(&x); + Test::destroy(&West::y); + return 0; +} diff --git a/tests/PlacemenNewTest.cpp b/tests/PlacemenNewTest.cpp new file mode 100644 index 0000000..db03eeb --- /dev/null +++ b/tests/PlacemenNewTest.cpp @@ -0,0 +1,21 @@ +#include + +template +struct Apple +{ + T x; +}; + + +int main() +{ + char buffer[sizeof(Apple)]; + + auto* f = new (&buffer) Apple; + + auto& r = *f; + + r.~Apple(); + + f->~Apple(); +} diff --git a/tests/PlacemenNewTest.expect b/tests/PlacemenNewTest.expect new file mode 100644 index 0000000..b32d2b9 --- /dev/null +++ b/tests/PlacemenNewTest.expect @@ -0,0 +1,28 @@ +#include + +template +struct Apple +{ + T x; +}; + +/* First instantiated from: PlacemenNewTest.cpp:12 */ +#ifdef INSIGHTS_USE_TEMPLATE +template<> +struct Apple +{ + int x; + // inline Apple() noexcept = default; +}; + +#endif + +int main() +{ + char buffer[4]; + Apple * f = new (reinterpret_cast(&buffer))Apple(); + Apple & r = *f; + r.~Apple(); + f->~Apple(); + return 0; +}