Compilation error - "explicit type is missing" When using friend constructor in template cla

I get errors when I try to compile a .cu file which has a templated class which friends a constructor of another templated class. I’ve tried to isolate the error below. When I compile this code in a .cu file:

template <typename>

class B;

template <typename T>

class A {


    A(const B<T>& b) {}

void foo(const B<T>& b) { }


template <typename S>

class B {


    template<typename T>

    friend A<T>::A(const B<T>& b);

template<typename T>

    friend void A<T>::foo(const B<T>& b);


I get the following error:

$ nvcc -c error: explicit type is missing ("int" assumed)

1 error detected in the compilation of "/tmp/tmpxft_00001e29_00000000-4_test.cpp1.ii".

It compiles fine when I put the exact same code in a .cpp file. I thought nvcc simply forwarded non-CUDA code to the configured C compiler, but apparently something else is happening here. I would be happy for any help with understanding this.

My system:

OS: Ubuntu 11.04 64-bit

Compiler: GCC 4.4.5

CUDA Toolkit: Version 4.0.17

This certainly looks like an issue in the CUDA compiler. It would be helpful if you could file a bug against the compiler, since you already have a minimal repro case in hand. There is a link on the registered developer website for filing bugs. Thank you for your help, and sorry about the inconvenience.

I’m not a registered developer yet (I made an application). This means I can’t access that page, right?

If someone who already is a regdev could do this now I would be grateful.

It has been a while since I myself signed up as a registered developer, but from what I recall your application should go through within a few days, provided you filled in the requested information on the application form. Should you experience undue delay, feel free to drop me a line using a PM (personal message) via this forum. Thank you for your patience.