3

I am on Visual Studio 2013 and is trying to compile a CUDA code that utilizes inheritance and C++11. The code below returns "modifier is not allowed on a destructor" error because of the "override".

// derived.cuh
class derived : public base
{
 public:
  derived();
  ~derived() override;
};

where the destructor of the base class is virtual. The exact same code compiles fine on Ubuntu. The exact same code also compiles fine with default Visual studio c++ compiler if I change the .cu and .cuh to .cpp and .h. C++11 is enabled because if the "override" is appended on a normal function it also compiles fine. See example below,

// derived2.cuh
class derived2 : public base
{
 public:
  derived2();
  ~derived2();

  void func() override;
};  

where func() is an virtual function in the base class.

How to get rid of the "modifier is not allowed on a destructor" error when compiled with nvcc in VS2013?

user3667089
  • 2,996
  • 5
  • 30
  • 56
  • 3
    @AndyG "`override` indicates you want you method to get called when accessed from a base class pointer or reference" No, `virtual` does that. `override` simply tells the compiler it must analyse whether the method (signature/overload) really overrides a prior base `virtual` function (i.e. does not accidentally create a _new_ overrid_able_ `virtual` function) and throw an error if not, letting the user catch accidental typos, etc. This does not affect how the function is used if successfully compiled, whatsoever. – underscore_d Jan 25 '16 at 20:06
  • 1
    VS2015 accepts the override specifier on the destructor. Your options are to upgrade, or drop the `override` on the destructor. Not sure what else you can do. – Praetorian Jan 25 '16 at 20:08
  • @Praetorian I think this should be an nvcc problem because I can append override on destructors for normal .cpp and .h classes and it compiles fine. I will try to get hold of a VS2015 and test it with nvcc and see how it goes though – user3667089 Jan 25 '16 at 20:10
  • 1
    Oh, missed the part where you said the code compiles if you put it in a .h file instead of a .cuh file. In that case, it's unlikely VS2015 will solve the problem, you probably need a newer nvcc compiler, if there is one. – Praetorian Jan 25 '16 at 20:13
  • @underscore_d: Thank you for the correction. – AndyG Jan 25 '16 at 20:37
  • What is your nvcc version? – havogt Jan 25 '16 at 21:29

1 Answers1

1

Filed this bug to NVIDIA, and they responded back that this will be fixed in the next CUDA release (presumably 8.0).

user3667089
  • 2,996
  • 5
  • 30
  • 56