我有一个通过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),
               ^


我该如何沉默?

我已经尝试过的


// NOLINT添加到a.cpp:33的末尾->无效
// NOLINT添加到qobject.h:242->无效
将qobject.h:242包裹在#ifndef __clang_analyzer__->中无效
将所有qobject.h包裹在#ifndef __clang_analyzer__->中无效
// 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__

最佳答案

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

07-26 05:15