Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Is the Standard's definition of std::is_destructible unclear?
- #include <cstdio>
- #include <type_traits>
- #include <utility>
- struct PrivateDestructor
- {
- public:
- void *TestFunction();
- void Destroy() { delete this; }
- private:
- ~PrivateDestructor() { }
- };
- void *PrivateDestructor::TestFunction()
- {
- typedef PrivateDestructor U;
- // Expression from the Standard is well-formed (evaluates here to "void")...
- decltype(std::declval<U&>().~U()) *ptr = this;
- return ptr;
- }
- int main()
- {
- // ...yet this is false in GCC and Clang. Is the Standard unclear?
- std::printf("%d\n", std::is_destructible<PrivateDestructor>::value);
- PrivateDestructor *obj = new PrivateDestructor();
- std::printf("%p\n", obj->TestFunction());
- obj->Destroy();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement