通过非POD类型可变参数函数是未定义行为? [英] Passing NON-POD type to Variadic function is undefined behavior?
问题描述
在这份文件中撰文称
只有POD类型可以是省略号的参数...,而的std :: string是不是一个POD类型。
Only a POD-type can be an argument for the ellipsis "..." while std::string is not a POD-type.
我理解这是传递非POD类型可变参数的功能是不确定的行为
。这对吗?结果
虽然,他在说C / C ++的标准呢?我试着在n3242 C ++规范找到它。但无法找到。
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.
我想知道我的理解正确,这是一个标准。
I'd like to know I'm understanding rightly and this is a standard.
推荐答案
它规定在C ++ 11 5.2.2 / 7:
It's specified in 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.
所以,就看每个编译器是否支持与否;便携式code不能依赖任何实现定义的行为。在旧的标准,它只是不确定的。
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.
这篇关于通过非POD类型可变参数函数是未定义行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!