沉默铿锵有力

时间:2016-11-16 21:06:00

标签: 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_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),
               ^

我怎能沉默这个?

我已经尝试过:

  1. // NOLINT添加到a​​.cpp的末尾:33 - &gt;没效果
  2. 在qobject.h的末尾添加// NOLINT:242 - &gt;没效果
  3. #ifndef __clang_analyzer__ - &gt;中换行qobject.h:242没效果
  4. #ifndef __clang_analyzer__ - &gt;中包装所有qobject.h没效果
  5. // NOLINT添加到connectImpl的所有行 - &gt; clang-tidy crashes
  6. @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__
    

2 个答案:

答案 0 :(得分:3)

我认为你必须对你的5行connectImpl()或类似内容进行评论,因为// NOLINT仅影响单个代码行。 (1)

答案 1 :(得分:0)

如果您在QtCreator中使用clang-tidy,请参见

https://bugreports.qt.io/browse/QTCREATORBUG-20744

QtCreator使用了额外的工具,而lib还不支持// NOLINT等。