Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About ODR-violations and template variables

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?

like image 488
Peregring-lk Avatar asked Sep 21 '17 05:09

Peregring-lk


1 Answers

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.

like image 151
T.C. Avatar answered Oct 23 '22 11:10

T.C.