c++language-lawyerc++17inline-variable

Why does cppreference define type_traits xxx_v shortcuts as inline constexpr and not just constexpr?


Why does cppreference define type_traits xxx_v shortcuts as inline constexpr and not just constexpr?

For example, see is_integral_v:

template< class T >
inline constexpr bool is_integral_v = is_integral<T>::value;

Is this just a matter of style or is there some difference in behavior? As far as I know constexpr variables are implicitly inline.

Edit: Looking at the draft of the latest standard, it also uses inline constexpr. The question actually applies to the standard, then.


Solution

  • [basic.link]/3.2 applies to names of "a non-inline variable of non-volatile const-qualified type". A variable template isn't a variable, just like a class template isn't a class, a function template isn't a function, and a cookie cutter isn't a cookie. So that rule doesn't apply to the variable template is_integral_v itself.

    A variable template specialization is a variable, however, so there are some questions about whether that rule gives it internal linkage. This is core issue 1713, the direction of which is that the rule is not applicable.

    Core issue 1713, however, wasn't resolved in time for C++17. So LWG decided to simply plaster inline all over the variable templates just to be safe, because they don't hurt, either.