Search code examples
c++templatesinlineautoc++20

Is "inline" required for "void f(auto) {}" in a header?


Consider

template<typename T>
inline void f(T) {} // "inline" can be safely removed.

and

inline void f(auto) {} // Can "inline" also be safely removed?

As per the C++ standard, can inline be safely removed in the latter case?


Solution

  • From [dcl.fct]/18:

    An abbreviated function template is a function declaration that has one or more generic parameter type placeholders ([dcl.spec.auto]). An abbreviated function template is equivalent to a function template ([temp.fct]) whose template-parameter-list includes one invented type template-parameter for each generic parameter type placeholder of the function declaration, in order of appearance.

    Emphasis added. That doesn't leave a lot of wiggle room for inline not being the default.