Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for pseudo destructor. #699

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions CodeGeneratorTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions tests/PlacemenNew2Test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <new>

namespace Test {
template<typename T>
struct Apple
{
T x;
};

template<typename T>
void destroy(T* ptr) {
ptr->T::~T();
}
}

namespace West
{
int y;
}

int main()
{
char buffer[sizeof(Test::Apple<int>)];

auto f = new (&buffer) Test::Apple<int>;

f->Test::Apple<int>::~Apple<int>();
f->~Apple();

Test::destroy(f);

int x;
Test::destroy(&x);

Test::destroy(&West::y);
}
66 changes: 66 additions & 0 deletions tests/PlacemenNew2Test.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include <new>

namespace Test
{
template<typename T>
struct Apple
{
T x;
};

/* First instantiated from: PlacemenNew2Test.cpp:23 */
#ifdef INSIGHTS_USE_TEMPLATE
template<>
struct Apple<int>
{
int x;
// inline Apple() noexcept = default;
};

#endif
template<typename T>
void destroy(T * ptr)
{
ptr->~T();
}

/* First instantiated from: PlacemenNew2Test.cpp:30 */
#ifdef INSIGHTS_USE_TEMPLATE
template<>
void destroy<Apple<int> >(Apple<int> * ptr)
{
ptr->~Apple();
}
#endif


/* First instantiated from: PlacemenNew2Test.cpp:33 */
#ifdef INSIGHTS_USE_TEMPLATE
template<>
void destroy<int>(int * ptr)
{
ptr->~int();
}
#endif


}

namespace West
{
int y;

}

int main()
{
char buffer[4];
Test::Apple<int> * f = new (reinterpret_cast<void *>(&buffer))Test::Apple<int>();
f->~Apple();
f->~Apple();
Test::destroy(f);
int x;
Test::destroy(&x);
Test::destroy(&West::y);
return 0;
}
21 changes: 21 additions & 0 deletions tests/PlacemenNewTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <new>

template<typename T>
struct Apple
{
T x;
};


int main()
{
char buffer[sizeof(Apple<int>)];

auto* f = new (&buffer) Apple<int>;

auto& r = *f;

r.~Apple<int>();

f->~Apple<int>();
}
28 changes: 28 additions & 0 deletions tests/PlacemenNewTest.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <new>

template<typename T>
struct Apple
{
T x;
};

/* First instantiated from: PlacemenNewTest.cpp:12 */
#ifdef INSIGHTS_USE_TEMPLATE
template<>
struct Apple<int>
{
int x;
// inline Apple() noexcept = default;
};

#endif

int main()
{
char buffer[4];
Apple<int> * f = new (reinterpret_cast<void *>(&buffer))Apple<int>();
Apple<int> & r = *f;
r.~Apple();
f->~Apple();
return 0;
}