Why C++ linker is silent about ODR violation?

后端 未结 2 2066
半阙折子戏
半阙折子戏 2020-12-21 09:06

Let\'s consider some synthetic but expressive example. Suppose we have Header.h:

Header1.h

#include 

// Define generic version
templ         


        
2条回答
  •  感情败类
    2020-12-21 09:21

    The compiler is silent, because it's not required to emit anything by [basic.def.odr/4]:

    Every program shall contain exactly one definition of every non-inline function or variable that is odr-used in that program outside of a discarded statement; no diagnostic required. The definition can appear explicitly in the program, it can be found in the standard or a user-defined library, or (when appropriate) it is implicitly defined (see [class.ctor], [class.dtor] and [class.copy]). An inline function or variable shall be defined in every translation unit in which it is odr-used outside of a discarded statement.

提交回复
热议问题