Can statically unreachable calls cause undefined help errors?

Consider the following code that has an unreachable call 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?

+4
source share
3 answers

++ §3.2/p4 [basic.def.odr] ( ):

, odr; . , ( ) (. 12.1, 12.4 12.8). , odr.

foo undefinedFunction, odr (.. undefinedFunction). , if . , , , , .

+4

, odr - : ([basic.def.odr]/5). , ([basic.def.odr]/2). typeid, sizeof, noexcept decltype, . , undefinedFunction odr, foo, . " " .

+7

, . , undefinedFunction() . symbols that are not defined ( ).

static_assert. undefined , , , , .

, - , . , , , , undefined , , .

, , GCC.

+1

All Articles