About ODR-violations and template variables

青春壹個敷衍的年華 提交于 2019-12-09 16:39:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!