Is the type of a function affected by the presence or absence of a function parameter pack in its parameter-declaration-clause?

Viewed 87

Consider the following:

#include <type_traits>

void f(int);
void g(auto ...);

static_assert(std::is_same_v<decltype(f), decltype(g<int>)>); // succeeds in GCC 12.1, Clang 14.0.0, and MSVC 19.30

[dcl.fct]/12 specifies that the parameter-type-list of a function is part of the function type (obviously):

The return type, the parameter-type-list, the ref-qualifier, the cv-qualifier-seq, and the exception specification, but not the default arguments or the trailing requires-clause, are part of the function type.

The last sentence of [dcl.fct]/5 specifies that the "presence or absence of ... a function parameter pack" is part of the function's parameter-type-list:

The resulting list of transformed parameter types and the presence or absence of the ellipsis or a function parameter pack is the function's parameter-type-list.

Since the non-template function f has no function parameter pack in its parameter list but variadic function template g does, would that not mean that their parameter-type-lists are different, and therefore their types are also?

1 Answers

Since the non-template function f has no function parameter pack in its parameter list but variadic function template g does, would that not mean that their parameter-type-lists are different, and therefore their types are also?

g is an Abbreviated Function Template. Being a template, it doesn't have a type of its own.

g<int>, on the other hand, is an instantiation of g. It produces a concrete function void g(int), which has the same type as f.

Related