5

I have a build which uses clang-tidy through cmake:

set_target_properties(project
    PROPERTIES
    ...
    CXX_CLANG_TIDY
        "/usr/bin/clang-tidy"
        "-checks=modernize-*,readability-*,performance-*"
        "-fix"
)

While building it I am getting a possible memory leak inside the Qt libraries:

/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),
               ^

How can I silence this?

What I already tried:

  1. Add a // NOLINT to the end of a.cpp:33 -> no effect
  2. Add a // NOLINT to the end of qobject.h:242 -> no effect
  3. Wrap qobject.h:242 in a #ifndef __clang_analyzer__ -> no effect
  4. Wrap all of qobject.h in a #ifndef __clang_analyzer__ -> no effect
  5. Add // NOLINT to all lines of connectImpl -> clang-tidy crashes

@Tarod: Here is what I currently have:

#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__
valiano
  • 16,433
  • 7
  • 64
  • 79
Mac
  • 3,397
  • 3
  • 33
  • 58

2 Answers2

3

I think you must comment all of your 5 lines of connectImpl() or similar since // NOLINT affects a single code line, only.(1)

falkb
  • 1,294
  • 11
  • 35
1

If you used clang-tidy in the QtCreator see

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

QtCreator uses the extra-tools and that lib doesnt support //NOLINT etc yet.

roy
  • 11
  • 2