1

Can one assume in unevaluated context, that (::new (std::declval< void * >()) T())->~T() is semantically (in sense of noexcept, but not in sense of type of expression) equivalent to simple T()? Assume that neither global, nor class-scope operator new are overloaded, if it mutters much.

Often in type traits T() used inside operator noexcept() to determine whether only the separate constructor is noexcept or not. Surely it is wrong.

To prevent the loss of generality one can assume that T() here is either a calling of a default constructor or of any other constructor.

Tomilov Anatoliy
  • 15,657
  • 10
  • 64
  • 169

1 Answers1

0

Can one assume in unevaluated context, that (::new (std::declval< void * >()) T())->~T() is semantically full equivalent to simple T()?

Nope, The last expression there is a destructor function, which is implicitly a void return type.

#include <new>
#include <type_traits>

struct T{int x; double y; };
int main(){
    constexpr int size = sizeof((::new (std::declval< void * >()) T())->~T());
}

The compiler should complain of trying to get the sizeof a void

WhiZTiM
  • 21,207
  • 4
  • 43
  • 68