Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress warnings for file included from header

I use GCC -Weffc++ option in my Qt project. To suppress warnings from Qt headers i add QMAKE_CXXFLAGS += -isystem $(QTDIR)\include.
But this doesn't suppress all warnings, i still get annoying warnings from QUuid class because $(QTDIR)\include\QtCore\quuid.h
file includes
..\..\src\corelib\plugin\quuid.h.
I tried to add
QMAKE_CXXFLAGS += -isystem $(QTDIR)\src
and
QMAKE_CXXFLAGS += -isystem $(QTDIR)\src\corelib\plugin
but it didn't help. Is there a way to fix this?

like image 625
WalterSullivan Avatar asked Jul 26 '12 06:07

WalterSullivan


People also ask

How do you suppress warnings in C++?

To disable a set of warnings for a given piece of code, you have to start with a “push” pre-processor instruction, then with a disabling instruction for each of the warning you want to suppress, and finish with a “pop” pre-processor instruction.

How do I supress a warning in GCC?

-w is the GCC-wide option to disable warning messages.

How do I disable GCC?

To answer your question about disabling specific warnings in GCC, you can enable specific warnings in GCC with -Wxxxx and disable them with -Wno-xxxx. From the GCC Warning Options: You can request many specific warnings with options beginning -W , for example -Wimplicit to request warnings on implicit declarations.


1 Answers

You need to suppress each directory separately. Example from my project:

QMAKE_CXXFLAGS += -isystem "$$[QT_INSTALL_HEADERS]/qt5" -isystem "$$[QT_INSTALL_HEADERS]/qt5/QtWidgets" \
                  -isystem "$$[QT_INSTALL_HEADERS]/QtXml" -isystem "/usr/include/qt5/QtGui" \
                  -isystem "$$[QT_INSTALL_HEADERS]/QtCore"

Or, to automate the above for the exact Qt modules you have enabled:

for (inc, QT) {
    QMAKE_CXXFLAGS += -isystem \"$$[QT_INSTALL_HEADERS]/Qt$$system("echo $$inc | sed 's/.*/\u&/'")\"
}

# Still need this separately:
QMAKE_CXXFLAGS += -isystem "$$[QT_INSTALL_HEADERS]/qt5"
like image 93
dismine Avatar answered Oct 06 '22 00:10

dismine