Is `clang-check` failing to honor `-isystem`?

二次信任 提交于 2019-12-08 02:55:41

问题


For both Clang and GCC, the -isystem flag adds a "system" include path, which causes the compiler not to emit warnings related to code found in those headers.

However, running clang-check on my code, I see the following warning:

In file included from <myfile>.cpp:1:
In file included from <Qt-path>/gcc_64/include/QtCore/QCoreApplication:1:
In file included from <Qt-path>/gcc_64/include/QtCore/qcoreapplication.h:40:
<Qt-path>/gcc_64/include/QtCore/qobject.h:235:16: warning: Potential memory leak
        return connectImpl(sender, reinterpret_cast<void **>(&signal),
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

...so it would appear that clang-check does not treat -isystem include paths differently from -I include paths. Am I misusing the tool or misinterpreting the output (i.e., is this actually a potential error in my code)? Is there another way to explicitly ignore errors from Qt headers when running clang-check?


回答1:


This is because you also have to include the "QtCore" directory via-"isystem", in addition to just the base Qt include directory. This is because Clang finds a more specific include (QT -Is the modules as well) and uses that. See the Clang Manual for -isystem information on how the includes work.

Effectively you want to do the following:

contains(QT,"core") {
QMAKE_CXXFLAGS *= $$join(QMAKE_INCDIR_QT, " -isystem", "-isystem", "/QtCore")
}

And repeat this for all standard Qt modules (Designer, Gui, Help, Network, etc).




回答2:


I had this problem and arrived at this question via search engine. So for anybody else like me; the answer is to use the -extra-arg twice!

For example

./MyTool -extra-arg="-isystem" -extra-arg="my/system/include/path" myfile.cpp

And you don't get all those warnings.



来源:https://stackoverflow.com/questions/31172832/is-clang-check-failing-to-honor-isystem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!