问题
I know that template functions don't suffer of multiple definitions when linking, like member functions defined inside a class, which are inline by default. Also, constexpr
objects have internal linkage, but template variables have external linkage (I mean at namespace scope and for C++14 in both cases).
What about?
template<class T>
constexpr T i_am_odr_safe{};
Does i_am_odr_safe
have external or internal linkage in C++14? and is it safe regarding multiple-definitions like function templates?
In other words, is i_am_odr_safe
odr-safe?
回答1:
This is core issue 1713, the direction of which IIRC is that this variable template will have external linkage.
And no, this hasn't been resolved yet, which is why LWG decided to plaster inline
all over the variable templates in the standard library when it adopted A+B2 of P0604R0.
来源:https://stackoverflow.com/questions/46335920/about-odr-violations-and-template-variables