-
Operating System: Observed on Fedora 13 64-bit and Fedora 9 32-bit
-
CUDA toolkit release version: 4.0
-
SDK release version: 4.0
-
Compiler for CPU host code: g++
-
Synopsis:
nvcc generates invalid compile error when compiling a templated sub-class with exception handling.
- Detailed description:
The following snippet is a simple instance of code that induces this bug.
#include <iostream>
template<typename T>
class Base {};
template<typename T>
class Test : public Base<T> {
public:
void test();
};
template<typename T>
void Test<T>::test() {
try { throw std::string("Exception test"); }
catch(std::string & e) { }
}
int main(int argc, char* argv[])
{
Test<int> test;
test.test();
}
When I try to compile this code as follows, I get the following errors:
nvcc Bug.cu
Bug.cu: In member function ‘void Test::test()’:
Bug.cu:15: error: expected `)’ before ‘(’ token
Bug.cu:15: error: expected `{’ before ‘(’ token
Bug.cu:15: error: ‘::e’ has not been declared
Bug.cu:15: error: expected `;’ before ‘)’ token
Upon further inspection (using the --keep and --verbose options), I noticed that nvcc is failing to compile the intermediate file Bug.cu.cpp. In Bug.cu.cpp nvcc has added parenteses and scoping to the exception variable in the catch statement:
# 15 "Bug.cu"
catch (::std::string &(::e)) { }
This behavior only seems to happen in the case that a templated class is inheriting another templated class. It appears that there is a bug in the generation of the host only code in this case.