多个翻译单元中函数模板实例化的标识

Identity of function template instantiation in multiple translation units

根据cppref,多个翻译单元中inline函数的身份特征如下:

...

2) It has the same address in every translation unit.

3) Function-local static objects in all function definitions are shared across all translation units (they all refer to the same object defined in one translation unit)

...

简单来说就是隐含了单例身份

我想知道这是否同样适用于函数模板实例化 没有 inline 说明符。

I'm wondering whether the same applies to function template instantiations without the inline specifier.

同样适用于模板。参见§3.2 一种定义规则:

  1. 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.6), 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.5) in a program provided that each definition appears in a different translation unit, and provided the definitions satisfy the following requirements. ... If D is a template and is defined in more than one translation unit, then the preceding requirements shall apply both to names from the template’s enclosing scope used in the template definition (14.6.3), and also to dependent names at the point of instantiation (14.6.2). If the definitions of D satisfy all these requirements, then the program shall behave as if there were a single definition of D. If the definitions of D do not satisfy these requirements, then the behavior is undefined.