I've been thinking of the following. Consider two files:
A.cpp:
template<class T> void g(T) {}
inline void f() { g(1); }
B.cpp:
template<class T> void g(T) {}
void g(int) {}
inline void f() { g(1); }
Without void g(int) {}
this program is 100% valid. With void g(int) {}
, g(1)
resolves to the template version in A.cpp and to the non-template in B.cpp.
Does this program violate ODR? Why?
Yes, it does. In the exception for inline
functions it's specified that not only shall the definitions of the inline function consist of exactly the same token sequence but that all the corresponding identifiers in the function definition which name entities outside of the function definition must refer to the same entity (with a few minor exceptions, such as referring to const objects with internal linkage with the same definition being allowed). [see ISO/IEC 14882:2003 3.2/5]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With