Passing NON-POD type to Variadic function is undefined behavior?

。_饼干妹妹 提交于 2019-11-27 04:45:48

问题


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.

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.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/10083844/passing-non-pod-type-to-variadic-function-is-undefined-behavior

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!