Qt 沉默的叮当声
我有一个通过cmake使用clang tidy的构建:Qt 沉默的叮当声,qt,cmake,clang-static-analyzer,clang-tidy,Qt,Cmake,Clang Static Analyzer,Clang Tidy,我有一个通过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_6
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),
^
我认为您必须对所有5行connectImpl()或类似内容进行注释,因为
//NOLINT
只影响单个代码行。如果您在QtCreator中使用了clang tidy,请参见
QtCreator使用了额外的工具,而lib还不支持//NOLINT等。
\ifndef\uu clangg\u分析器
应该可以工作。您是否将#endif
放在qobject.h
文件的末尾?如果您将#ifndef(ifndef)clangg(analyzer)放在qobject.h
文件的开头,我会更新同样的问题。@Tarod将整个文件添加到了#ifndef中并仍然打印错误…嗯。。。您是否可以尝试使用ifdef
而不是ifndef
?我只是想看看分析结果的不同如果我这么做的话。。。运行“/usr/bin/clang-tidy”muahahaha时出错,这看起来像是一个经过良好测试的工具…;)你用他们的最新版本吗?是的,我用的是最新版本。3.9.1
#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__