标准有误?

1 c++ standards

§5/ 4 C++标准

i = 7, i++, i++;  // i becomes 9
i = ++i + 1;  //the behavior is unspecified
Run Code Online (Sandbox Code Playgroud)

应该改为

i = 7, i++, i++;  // the behavior is undefined
i = ++i + 1;  //the behavior is undefined
Run Code Online (Sandbox Code Playgroud)

对?

CB *_*ley 7

是的,请参阅此缺陷报告:http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#351.

澄清:示例是错误的,但第一个声明的"修复"不正确.第一个语句在标准中正确评论.这只是第二个不准确的评论.


Pra*_*rav 6

i = 7, i++, i++; // i becomes 9
Run Code Online (Sandbox Code Playgroud)

很好.运算符的=优先级高于,表达式等效的优先级

(i = 7), i++, i++; 
Run Code Online (Sandbox Code Playgroud)

这是一个完美定义的行为,因为它,是一个序列点.

据,直到...为止

i = ++i + 1; //the behavior is unspecified
Run Code Online (Sandbox Code Playgroud)

我担心C++ 03中的行为是未定义的,在C++ 0x中定义良好.如果您有C++ 0x草案,可以查看部分1.9/15

i = i++ + 1; // the behavior is unde?ned
Run Code Online (Sandbox Code Playgroud)