Consider the following code that has an unreachable call undefinedFunction.
undefinedFunction
void undefinedFunction(); template <bool b = false> void foo() { static_assert(b == false); if (b) undefinedFunction(); } int main() { foo(); }
GCC compiles and links this without complaint. Using static_assertit is difficult to understand how the compiler can do something else, but is there anything in the standard to say about it? What to do if static_assertdeleted? Is the compiler generally required to delete a branch, or can it actually fix an unreachable call statement that will cause the linker to complain?
static_assert
++ §3.2/p4 [basic.def.odr] ( ):
, odr; . , ( ) (. 12.1, 12.4 12.8). , odr.
foo undefinedFunction, odr (.. undefinedFunction). , if . , , , , .
foo
if
, odr - : ([basic.def.odr]/5). , ([basic.def.odr]/2). typeid, sizeof, noexcept decltype, . , undefinedFunction odr, foo, . " " .
typeid
sizeof
noexcept
decltype
, . , undefinedFunction() . symbols that are not defined ( ).
undefinedFunction()
symbols that are not defined
static_assert. undefined , , , , .
, - , . , , , , undefined , , .
, , GCC.