我有一个通过 cmake 使用 clang-tidy 的构建:
set_target_properties(project
PROPERTIES
...
CXX_CLANG_TIDY
"/usr/bin/clang-tidy"
"-checks=modernize-*,readability-*,performance-*"
"-fix"
)
在构建它时,我在 Qt 库中遇到了可能的内存泄漏:
/opt/Qt5.7.0/5.7/gcc_64/include/QtCore/qobject.h:242:16: warning: Potential memory leak [clang-analyzer-cplusplus.NewDeleteLeaks]
return connectImpl(sender, reinterpret_cast<void **>(&signal),
^
.../a.cpp:27:5: note: Taking false branch
if (not inputQFile.makeAbsolute()) {
^
.../a.cpp:33:5: note: Calling 'QObject::connect'
connect(this, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
^
/opt/Qt5.7.0/5.7/gcc_64/include/QtCore/qobject.h:238:13: note: Left side of '||' is false
if (type == Qt::QueuedConnection || type == Qt::BlockingQueuedConnection)
^
/opt/Qt5.7.0/5.7/gcc_64/include/QtCore/qobject.h:238:9: note: Taking false branch
if (type == Qt::QueuedConnection || type == Qt::BlockingQueuedConnection)
^
/opt/Qt5.7.0/5.7/gcc_64/include/QtCore/qobject.h:242:16: note: Potential memory leak
return connectImpl(sender, reinterpret_cast<void **>(&signal),
^
我怎样才能让这个静音?
我已经尝试过的:
- 在 a.cpp:33 末尾添加 a
// NOLINT
-> 无效 - 在 qobject.h:242 的末尾添加 a
// NOLINT
-> 无效 - 将 qobject.h:242 包裹在一个
#ifndef __clang_analyzer__
-> 没有效果 - 将所有 qobject.h 包裹在一个
#ifndef __clang_analyzer__
-> 没有效果 - 添加
// NOLINT
到 connectImpl 的所有行 -> clang-tidy crashs
@Tarod:这是我目前拥有的:
#ifndef __clang_analyzer__
return connectImpl(sender, reinterpret_cast<void **>(&signal),
receiver, reinterpret_cast<void **>(&slot),
new QtPrivate::QSlotObject<Func2, typename QtPrivate::List_Left<typename SignalType::Arguments, SlotType::ArgumentCount>::Value, // NOLINT
typename SignalType::ReturnType>(slot),
type, types, &SignalType::Object::staticMetaObject); // NOLINT
#endif //__clang_analyzer__