Why doesn't this “undefined extern variable” result in a linker error in C++17?

前端 未结 4 1013
后悔当初
后悔当初 2021-02-05 00:43

I have compiled and ran the following program in a C++17 compiler (Coliru). In the program, I declared an extern variable, but did not defi

4条回答
  •  情话喂你
    2021-02-05 01:46

    Because the compiler produces compiler errors, the linker would yield linker errors ...

    No, seriously:

    if constexpr (true)
    

    is always true, so the compiler ignores the rest of the if-clause because it is never reached. So i is never used actually.

提交回复
热议问题