The warning is that name will have a different address in each source file that includes test.h Since it has an internal connection ( static ), each translation unit will receive its own copy; it will not be merged by the linker. This means that your code is equivalent:
template<int> struct base { ... }; static constexpr int val = some_value_different_in_every_source_file; struct type: base<val> {};
Your code is legal as presented, but if you include test.h in another source file, it breaks the rule with one definition:
3.2 One definition rule [basic.def.odr]
[...]
6 - There may be more than one class type definition [...] provided [...]: [...]
- in each definition of
D , the corresponding names [...] can refer to a const object with internal or no binding [only] if the value (but not the address) of the object [...] is used [...]
You use the address of the object with internal binding in the definition of the class type, so its use in several translation units is undefined behavior.
source share