3

The following code

#include <iostream>

template <class... Ts>
struct A
{
    template <Ts ...Args>
    static void f() {
        (std::cout << ... << Args) << std::endl;
    }
};

int main() {
    A<int, int, int, int>::f<0, 1, 2, 3>();
}

with -std=c++17, compiles with clang 12.0.1 and prints 0123, but fails to compile with g++ 11.1 with the following error:

test.cpp: In function ‘int main()’:
test.cpp:13:41: error: no matching function for call to ‘A<int, int, int, int>::f<0, 1, 2, 3>()’
   13 |     A<int, int, int, int>::f<0, 1, 2, 3>();
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
test.cpp:7:17: note: candidate: ‘template<Ts ...Args> static void A<Ts>::f() [with Ts ...Args = {Args ...}; Ts = {int, int, int, int}]’
    7 |     static void f() {
      |                 ^
test.cpp:7:17: note:   template argument deduction/substitution failed:
test.cpp:13:41: error: wrong number of template arguments (4, should be 1)
   13 |     A<int, int, int, int>::f<0, 1, 2, 3>();
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
test.cpp:7:17: note: provided for ‘template<Ts ...Args> static void A<Ts>::f() [with Ts ...Args = {Args ...}; Ts = {int, int, int, int}]’
    7 |     static void f() {
      |                 ^

Which is the correct behavior?

1

1 Answer 1

3

This is clearly a GCC bug. There are several bug reports, for example, 77731, 88580 and 91247. It will be fixed in GCC 12.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.