将NON-POD类型传递给Variadic函数是不确定的行为?

时间:2020-12-27 22:46:24

In this document, the author said

在这份文件中,作者说

Only a POD-type can be an argument for the ellipsis "..." while std::string is not a POD-type.

只有POD类型可以作为省略号“...”的参数,而std :: string不是POD类型。

I'm understanding this as Passing NON-POD type to Variadic function is undefined behavior. Is it right?
Though, is he saying C/C++ standard? I tried to find it at n3242 C++ spec. But can not find.

我理解这一点,因为将NON-POD类型传递给Variadic函数是未定义的行为。这样对吗?虽然,他是说C / C ++标准吗?我试图在n3242 C ++规范中找到它。但是找不到。

I'd like to know I'm understanding rightly and this is a standard.

我想知道我的理解是正确的,这是一个标准。

1 个解决方案

#1


8  

It's specified in C++11 5.2.2/7:

它在C ++ 11 5.2.2 / 7中指定:

Passing a potentially-evaluated argument of class type having a non-trivial copy constructor, a non-trivial move contructor, or a non-trivial destructor, with no corresponding parameter, is conditionally-supported with implementation-defined semantics.

通过实现定义的语义有条件地支持传递具有非平凡复制构造函数,非平凡移动构造函数或非平凡析构函数的类类型的潜在评估参数,其中没有相应的参数。

So it's up to each compiler whether to support it or not; portable code can't rely on any implementation defined behaviour. In older standards, it was simply undefined.

因此,每个编译器是否支持它都取决于它;可移植代码不能依赖任何实现定义的行为。在旧标准中,它只是未定义。

#1


8  

It's specified in C++11 5.2.2/7:

它在C ++ 11 5.2.2 / 7中指定:

Passing a potentially-evaluated argument of class type having a non-trivial copy constructor, a non-trivial move contructor, or a non-trivial destructor, with no corresponding parameter, is conditionally-supported with implementation-defined semantics.

通过实现定义的语义有条件地支持传递具有非平凡复制构造函数,非平凡移动构造函数或非平凡析构函数的类类型的潜在评估参数,其中没有相应的参数。

So it's up to each compiler whether to support it or not; portable code can't rely on any implementation defined behaviour. In older standards, it was simply undefined.

因此,每个编译器是否支持它都取决于它;可移植代码不能依赖任何实现定义的行为。在旧标准中,它只是未定义。