https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120759
Bug ID: 120759
Summary: Empty initializer list (`{}`) in a parameter pack
disables deduction for the entire pack
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mital at mitalashok dot co.uk
Target Milestone: ---
The following compiles with `-std=c++11 -fsyntax-only`
<https://godbolt.org/z/e7bKvxjvE>:
template<typename... T>
struct X {};
template<typename... T>
void f(X<T...>, T...);
int main() {
f(X<int, int>{}, {}, 1L);
f(X<int, int>{}, 1L, {});
}
This diverges from Clang, which fails to compile this with the following
diagnostic:
<source>:8:5: error: no matching function for call to 'f'
8 | f(X<int, int>{}, {}, 1L);
| ^
<source>:5:6: note: candidate template ignored: deduced conflicting types for
parameter 'T' (<int, int> vs. <(no value), long>)
5 | void f(X<T...>, T...);
| ^
<source>:9:5: error: no matching function for call to 'f'
9 | f(X<int, int>{}, 1L, {});
| ^
<source>:5:6: note: candidate template ignored: deduced conflicting types for
parameter 'T' (<int, int> vs. <long, (no value)>)
5 | void f(X<T...>, T...);
And a similar error with MSVC. All three compilers accept `{}, 1` or `1, {}`.
I believe GCC is interpreting <https://wg21.link/temp.deduct.call#1.sentence-4>
> an initializer list argument causes the parameter to be considered a
> non-deduced context.
... as making that entire parameter pack a non-deduced context, which is
unexpected. Clang and MSVC seem to interpret it as only that specific position
in the parameter pack become non-deduced.