Bug: nvcc and gcc 4.9.3 get into conflict over unnamed type template parameters

Consider the following minimal example:

template<class T, int>
struct A
{
    A() = default;
    A(int) : A() {}
};

int main()
{
    return 0;
}

Compiling with “nvcc -std c+11 -o bug bug.cu” (and, as I am on Arch Linux, ccbin set to a vanilla gcc 4.9.3) returns the following error message:

bug.cu: In constructor ‘A<T, <anonymous> >::A(int)’:
bug.cu:5:18: error: ‘__T0’ was not declared in this scope
     A(int) : A() {}
                  ^
bug.cu:5:22: error: template argument 2 is invalid
     A(int) : A() {}
                      ^
bug.cu:5:24: error: expected ‘{’ before ‘(’ token
     A(int) : A() {}
                        ^

When looking at the preprocessed files nvcc transformed the struct to this:

template< class T, int >
struct A {
A() = default;
A(int) : ::A< T, __T0> () { }
};

__T0 is of course undefined and thus causes an error once gcc takes over.

I am posting this here as I am somehow not allowed to file a bug on the official bug tracker despite being an “approved” developer.

I am using CUDA Toolkit v7.0 and I am on the x86_64 platform.

Arch Linux is not an officially supported platform, AFAIK.

I don’t believe this is a valid compile switch:

nvcc -std c+11

You don’t mention which version of nvcc (i.e. CUDA) you are using, but even CUDA 7.5RC docs list only up to gcc 4.9.2 as officially supported. I don’t believe gcc 4.9.3 is officially supported by nvcc up through CUDA 7.5

When I compile your code on nvcc 7.5.6 (CUDA 7.5RC) and gcc 4.8.2 (an explicitly listed supported version) I get no errors.

You may want to switch to a supported configuration.