Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdint>
- #include <cstdio>
- #include <functional>
- class TestClass {
- public:
- void* self = nullptr;
- // This works
- // std::aligned_storage<sizeof(uint64_t), sizeof(uint64_t)>::type data;
- // This breaks
- alignas(uint64_t) char buffer[sizeof(uint64_t)];
- TestClass() { self = this; }
- ~TestClass()
- {
- if (self != (void*)this) {
- // If this is reached, the object was moved using a simple memcpy, not using the constructors
- printf("Bug!");
- }
- }
- TestClass(const TestClass& o)
- : TestClass()
- {
- }
- TestClass(TestClass&& o)
- : TestClass()
- {
- }
- TestClass& operator=(TestClass&&) noexcept { return *this; }
- TestClass& operator=(const TestClass&) noexcept { return *this; }
- };
- std::function<void*()> testLambda()
- {
- const TestClass test{};
- return [=]() { return test.self; };
- }
- int main()
- {
- testLambda();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement