Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) How to suppress -Weffc++ errors?

 

How to suppress -Weffc++ errors? is a FAQ to suppress the -Weffc++ flag, for example, when using Qt.

 

 

 

 

 

 

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: CppSuppressEffCppErrors.pro

 

TEMPLATE = app
CONFIG += console
CONFIG -= qt
QMAKE_CXXFLAGS += -std=c++11 -Werror -Wextra -Weffc++
SOURCES += main.cpp


 

 

 

 

 

main.cpp

 

#include <vector>

#pragma GCC diagnostic ignored "-Weffc++"

///Suppress:
///error: 'MyClass::m_v' should be initialized in the member initialization list [-Werror=effc++]
struct MyClass
{
  MyClass() {}
  std::vector<int> m_v;
};

#pragma GCC diagnostic pop

///Unsupress
///error: 'MyClass2::m_v' should be initialized in the member initialization list [-Werror=effc++]
struct MyClass2
{
  MyClass2() {} //Will not compile
  std::vector<int> m_v;
};

int main()
{
  MyClass v;
}

 

 

 

 

 

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

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml