Does initialization entail lvalue-to-rvalue conversion? Is `int x = x;` UB?

前端 未结 4 590
天涯浪人
天涯浪人 2020-11-22 07:50

The C++ standard contains a semi-famous example of \"surprising\" name lookup in 3.3.2, \"Point of declaration\":

int x = x;

This initializ

4条回答
  •  余生分开走
    2020-11-22 08:05

    this is not undefined behaviour.You just don't know its specific values, because there is no initialization. If the variable is global and built-in type so the compiler will put it initialized to the right value. If the variable is local so the compiler not initialize it,So all of the variables are initialized to yourself, don't rely on the compiler.

提交回复
热议问题