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

前端 未结 4 1017
后悔当初
后悔当初 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:32

    Because the variable isn't odr-used. You have a constexpr if there that always discards the branch that could use it.

    One of the points of constexpr if is that the discarded branch need not even compile, only be well-formed. That's how we can place calls to non-existing member functions in a discarded branch.

提交回复
热议问题