1

According to this answer constexpr function are always inline.

A template function can be declared constexpr even if all specialization does not fulfill the requirements to be a constexpr function. In this last case, the specialization is not constexpr.

For example:

template<class T>
constexpr decltype(auto) size(const T& a){
   return a.size();
}
std::array<int,10> arr;
std::vector<int> vec;
size(arr);//constexpr
size(vec);//not a constexpr;

The instantiation size<std::vector> is not constexpr, but is it inline?

Community
  • 1
  • 1
Oliv
  • 17,610
  • 1
  • 29
  • 72
  • I suspect it still bears the implicit `inline` specifier. However, it's still up to the compiler to actually `inline` it, with the special case of making it possible to have multiple definitions in various translation units – WhiZTiM Mar 16 '17 at 13:09
  • 1
    Consider adding a `language-lawyer` tag – alexeykuzmin0 Mar 16 '17 at 13:15
  • 1
    "Since C++17 a template function can be declared constexpr even if all specialization does not fulfill the requirements to be a constexpr function." That's been the case since C++11. – T.C. Mar 16 '17 at 18:52
  • OK, I correct it. – Oliv Mar 16 '17 at 21:32

1 Answers1

3

Yes; citing N4640, [dcl.constexpr]/1:

… A function or static data member declared with the constexpr specifier is implicitly an inline function or variable. …

The key here is "declared with" – the declaration is what matters, not the satisfaction of constexpr requirements.

ildjarn
  • 62,044
  • 9
  • 127
  • 211