NVCC in CUDA 9.2x (with GCC 6 - if relevant) does seem to mishandle “injected-class-name” see (C++ 2014 Standard draft: 14.6.1 - http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf ) where
following code compiles fine under G++ or even NVCC when compiled as *.cpp file, but fails with
main.cu(XXX): error: no instance of function template "Foo<T>::Bar [with T=int]" matches the argument list detected during instantiation of "void Foo<T>::Bar2() [with T=int]" (XXX): here
when compiled with NVCC as *.cu file.
template<typename T>
class Foo {
public:
template<template<typename> class VT>
void Bar() {}
void Bar2() {
Bar<Foo>();
}
};
int main(int argc, char *argv[])
{
Foo<int> foo;
foo.Bar2();
return 0;
}
The code can be fixed by explicitly specifying that Foo in “Bar();” refers to class template itself (as opposed to specialization) - this should be implicit behavior (according to aforementioned C++ standard - section 14.6.1 examples 1,2). Explicit reference to the class template seems to be possible by using full template name as in “Bar<::Foo>();” (or any other namespaces in which template lives).
Following code them compiles when both compiling with NVCC and as *.cu file.
template<typename T>
class Foo {
public:
template<template<typename> class VT>
void Bar() {}
void Bar2() {
Bar<::Foo>();
}
};
int main(int argc, char *argv[])
{
Foo<int> foo;
foo.Bar2();
return 0;
}