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.
答案 0 :(得分:0)
可以假设在未评估的上下文中,
(::new (std::declval< void * >()) T())->~T()
在语义上完全等同于简单T()
?
不,最后一个表达式是析构函数,它隐式地是void
返回类型。
#include <new>
#include <type_traits>
struct T{int x; double y; };
int main(){
constexpr int size = sizeof((::new (std::declval< void * >()) T())->~T());
}
编译器应该抱怨试图让sizeof
成为void