沉默铿锵有力

Mac*_*Mac 5 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"
)
Run Code Online (Sandbox Code Playgroud)

构建它时,我在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),
               ^
Run Code Online (Sandbox Code Playgroud)

我该如何沉默呢?

我已经尝试过的:

  1. 添加// NOLINT到a.cpp的末尾:33 - >无效
  2. 添加// NOLINT到qobject.h的末尾:242 - >没有效果
  3. 换行qobject.h:242 in #ifndef __clang_analyzer__- >无效
  4. 将所有qobject.h包装在#ifndef __clang_analyzer__- >无效
  5. 添加// NOLINT到connectImpl的所有行 - > clang-tidy崩溃

@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__
Run Code Online (Sandbox Code Playgroud)

fal*_*lkb 3

我认为您必须注释所有 5 行 connectImpl() 或类似内容,因为// NOLINT仅影响单个代码行。(1)

  • muahaha,这看起来像是一个经过充分测试的工具...;)您使用他们的最新版本吗? (3认同)