【问题标题】:Silencing clang-tidy沉默铿锵
【发布时间】:2016-11-16 21:05:59
【问题描述】:

我有一个通过 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. 在 a.cpp:33 末尾添加 // NOLINT -> 无效
  2. 在 qobject.h:242 的末尾添加 // NOLINT -> 无效
  3. 将 qobject.h:242 包装在 #ifndef __clang_analyzer__ 中 -> 无效
  4. 将所有 qobject.h 包装在 #ifndef __clang_analyzer__ 中 -> 无效
  5. 将 // NOLINT 添加到 connectImpl 的所有行 -> clang-tidy 崩溃

@塔罗德: 这是我目前拥有的:

#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__

【问题讨论】:

  • #ifndef __clang_analyzer__ 应该可以工作。您是否将#endif 放在qobject.h 文件的末尾?
  • @Tarod 我更新了问题
  • 如果您将#ifndef __clang_analyzer__ 放在qobject.h 文件的开头,同样的问题?
  • @Tarod 在#ifndef 中添加了整个文件,但仍然打印错误...
  • 嗯...你能用ifdef代替ifndef吗?只是为了看看分析中的差异。

标签: qt cmake clang-static-analyzer clang-tidy


【解决方案1】:

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

【讨论】:

  • 如果我这样做会使 clang-tidy 崩溃... 运行时出错 '/usr/bin/clang-tidy'
  • muahaha,这看起来像是一个经过充分测试的工具... ;) 你使用他们的最新版本吗?
  • 是的,我确实使用了最新版本。 3.9.1
【解决方案2】:

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

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

QtCreator 使用额外的工具,并且该库还不支持 //NOLINT 等。

【讨论】:

    猜你喜欢
    • 2013-12-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-25
    • 1970-01-01
    • 2016-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多