Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) -Weffc++

 

When adding -Weffc++ to a Qt Creator project file like below, extra compile warnings from 'Effective C++' by Scott Meyers will be given to help you.

 

QMAKE_CXXFLAGS += -Weffc++

 

-Weffc++ does not go together smoothly with Qt, however. See -Weffc++ and Qt how to possibly resolve this.

 

Compile cleanly at high warning levels [1]. Prefer compile errors to runtime errors [2].

 

 

 

 

 

How to add the -Weffc++ compiler option in your code?

 

Add the following line to your code:

 

#pragma GCC diagnostic warning "-Weffc++"

 

 

 

 

 

 

How to temporarily suppress the -Weffc++ compiler option?

 

Sometimes suppressing -Weffc++ is the lesser evil (for example when creating a derived class from std::binary_function).

 

Add the line below to your code to start suppressing the -Weffc++ compile warnings:

 

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
//Your code
#pragma GCC diagnostic pop

 

 

 

 

 

Qt -Weffc++ and Qt

 

-Weffc++ does not go together smoothly with Qt, however. See -Weffc++ and Qt how to possibly resolve this.

 

 

 

 

 

References

 

  1. Herb Sutter, Andrei Alexandrescu. C++ coding standards: 101 rules, guidelines, and best practices. 2005. ISBN: 0-32-111358-6. Item 1: 'Compile cleanly at high warning levels'.
  2. Herb Sutter, Andrei Alexandrescu. C++ coding standards: 101 rules, guidelines, and best practices. ISBN: 0-32-111358-6. Item 14: 'Prefer compile- and link-time errors to run-time errors'.

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict