“clang-check”是否未能遵守“-isystem”



对于Clang和GCC,-isystem标志添加一个"system"包含路径,这会导致编译器不会发出与这些标头中的代码相关的警告。

但是,在我的代码上运行clang-check,我看到以下警告:

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.

。因此,clang-check似乎不会-isystem包含路径与-I包含路径区别对待。我是否误用了该工具或误解了输出(即,这实际上是我的代码中的潜在错误(?有没有另一种方法可以在运行 Qt 标头时显式忽略 Qt 标头中的错误clang-check

这是因为除了基本的Qt include目录之外,您还必须通过"isystem"包含"QtCore"目录。 这是因为Clang找到了一个更具体的包含(QT - 也是模块(并使用它。 请参阅 Clang 手册,了解 -isystem 中有关包含如何工作的信息。

实际上,您希望执行以下操作:

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

并对所有标准Qt模块(Designer,GUI,Help,Network等(重复此操作。

我遇到了这个问题,并通过搜索引擎得出了这个问题。 所以对于像我这样的其他人;答案是使用 -extra-arg 两次!

例如

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

而且你不会得到所有这些警告。

最新更新