0

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.

ugoren
  • 16,023
  • 3
  • 35
  • 65

1 Answers1

5

It should be

Run<T>::template run<Args...>(args...);

Run<int> is non dependent template whereas Run<T> is.

BTW, in your example, you don't even need to specify arguments, and just let deduction occur:

Run<int>::run(args...);
Run<T>::run(args...);
StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458
Jarod42
  • 203,559
  • 14
  • 181
  • 302
  • Works great. I can't rely on deduction in my real code, because of trouble with references (I construct function types which must match exactly, long story). – ugoren Sep 27 '17 at 08:44