How is a situation when different implementations of an inline function are linked into one executable classified?

前端 未结 1 1678
别跟我提以往
别跟我提以往 2021-01-18 06:33

According to One Definition Rule (ODR) I can\'t have a function

void function()
{
}

defined more than once in one executable - linker will

相关标签:
1条回答
  • 2021-01-18 06:59

    Yes, it is UB for inline functions with external linkage (I think that's what the OP intends).

    $3.2/5-

    There can be more than one definition of a class type (clause 9), enumeration type (7.2), inline function with external linkage (7.1.2), class template (clause 14), non-static function template (14.5.5), static data member of a class template (14.5.1.3), member function of a class template (14.5.1.1), or template specialization for which some template parameters are not specified (14.7, 14.5.4) in a program provided that each definition appears in a different translation unit, and provided the definitions satisfy the following requirements.

    Given such an entity named D defined in more than one translation unit, then

    — each definition of D shall consist of the same sequence of tokens; and

    The same paragraph at the end states that failure to meet these requirements leads to UB

    0 讨论(0)
提交回复
热议问题