Consider the following example:
template<typename T>
class Foo
{
public:
Foo() {}
Foo(const Foo &);
};
// here it fails
template<typename T>
Foo<T>::Foo(const Foo &) = default;
int main () {
Foo<int> f;
return 0;
}
Saving this as test.cu and compiling with nvcc -std=c++11 results in this error:
$ nvcc -std=c++11 test.cu -o test
test.cu:11:44: error: expected ‘;’ before ‘=’ token
This code is perfectly valid by the C++11 standard, yet compilation with nvcc fails horibly. After some digging, I discovered that when compiled with --verbose --keep, the file test.cu.cpp.ii generated by cudafe++ contains the following snippet:
# 10 "nvcc_test.cu"
template < typename T >
Foo < T > :: Foo ( const Foo & ) = default = default
which is not even a valid C++ code (by any standard) so throwing it to GCC results in the above error.
Although this bug has been discovered on a system using GCC 5.1 (see the original bug report), the minimal example does not compile even on systems with older GCC versions (tested with 4.8.2). So nvcc must have worked only because nobody tried to use this syntax before, but this is not the case since GCC 5.1 where it is used in the STL itself (see the streambuf header).