mercredi 27 septembre 2017

expected primary-expression before '...' token calling templated method of templated class

I have a templated static method in a templated class, and I'm calling it from a templated function. Compilation fails with the error error: expected primary-expression before '...' token.

Here's a sample code. It has some unused template parameters, but fails exectly the same as my real code, where these parameters are important.

temp late<typename T>
class Run {
public:
    template<typename ...Args>
    static void run(Args... args) {}
};

template <typename T, typename ...Args>
void
run2(Args ...args)
{
    Run<int>::run<Args...>(args...);   // OK
    Run<T>::run<Args...>(args...);     // Fail on first . in Args...
}

int main() {
    run2<int>(1, 2, 3);
    return 0;
}

Compilation errors:

%  g++ -std=gnu++11 -o try try.cc
try.cc: In function 'void run2(Args ...)':
try.cc:13:21: error: expected primary-expression before '...' token
     Run<T>::run<Args...>(args...);     // Fail on first . in Args...
                     ^
try.cc:13:21: error: expected ';' before '...' token

Used gcc 4.8.5 on Ubuntu. Also reproduces with gcc 6.3

Any idea what's going on? The difference between the working line (with <int>) and the failing line (with <T>) is particularly confusing.

Aucun commentaire:

Enregistrer un commentaire