Why does the C ++ 17 GCC compiler warn about undefined?

According to C ++ 17, there is no guarantee for the evaluation order in the following expression. This is called unspecified behavior.

int i = 0;
std::cout<<i<<i++<<std::endl;

C ++ 17 The GCC compiler gives the following warning: Live Demo

prog.cc: In function 'int main()':
prog.cc:6:20: warning: operation on 'i' may be undefined [-Wsequence-point]
     std::cout<<i<<i++<<std::endl;

I don’t understand, in C ++ 17 above they express no longer undefined behavior, and then Why does the compiler give a warning about undefined?

+4
source share
1 answer

Gcc seems to give a warning because it is an angular register, or at least very close to being one. Portability seems to be one of the problems.

From the page https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

++ 17 : , , , undefined. , undefined C ++.

, . , , GCC, http://gcc.gnu.org/readings.html.

+5

Source: https://habr.com/ru/post/1690389/


All Articles