Abhijit
Abhijit

Reputation: 63737

Convert Warning to Error

In Windows, VC++ has a nifty option /We to convert a specific warning to error. Also every warning emitted by VC++ has a warning number for example

warning C4265: 'CFoo' : class has virtual functions, but destructor is not virtual

So it easy to identify the number and add a compiler option using the /We switch as /We4265

I checked the g++ documentation and found something similar (I believe), -Werror=, but the documentation mentions

Make the specified warning into an error.

But my question is,

Given a compiler warning

/yada/yada/src/inc/module.h:580: warning: 'struct IFoo' has virtual functions but non-virtual destructor

How do I convert this to error using the -Werror compiler option?

Upvotes: 2

Views: 2274

Answers (3)

Csq
Csq

Reputation: 5855

Compile the code with a later version of g++ or Clang++, they emit the name of the warnings as well.

$ clang++ -Wall -Wextra -Werror=non-virtual-dtor test.cpp
test10.cpp:4:3: error: 'X' has virtual functions but non-virtual destructor
      [-Wnon-virtual-dtor]
  ~X(){}
  ^
1 error generated.

Upvotes: 1

tklauser
tklauser

Reputation: 241

Either specify -Werror without any arguments to turn all warnings into errors, thus also the one above you're interested in. If you're only interested in turning that specific warning into an error, you can cause g++ to print the error switch in verbose mode. Newer versions of g++ even do this automatically.

Upvotes: 1

unwind
unwind

Reputation: 399871

That very sentence in the manual continues, with the answer:

The specifier for a warning is appended; for example -Werror=switch turns the warnings controlled by -Wswitch into errors. This switch takes a negative form, to be used to negate -Werror for specific warnings; for example -Wno-error=switch makes -Wswitch warnings not be errors, even when -Werror is in effect.

I'm not 100% sure, but -Wdelete-non-virtual-dtor might be the warning in question, so you'd need -Werror=delete-non-virtual-dtor.

Upvotes: 3

Related Questions