<div dir="ltr">Hi Artem,<div><br></div><div>Thanks for the email. Could you let me know exactly what you need?</div><div><br></div><div>If I run clang with the --analyze flag I get a simpler log than the one clang-tidy generates (same problem though):</div><div><div><br></div><div>...</div><div>[ 75%] Building CXX object CMakeFiles/main.dir/main_automoc.cpp.o</div><div>In file included from /mnt/e/_working/tidy/main.cpp:2:</div><div>In file included from /opt/Qt5.7.0/5.7/gcc_64/include/QtCore/QObject:1:</div><div>/opt/Qt5.7.0/5.7/gcc_64/include/QtCore/qobject.h:343:16: warning: Potential memory leak</div><div>        return connectImpl(sender, reinterpret_cast<void **>(&signal), context, Q_NULLPTR,</div><div>               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</div><div>1 warning generated.</div><div>[100%] Linking CXX executable main</div><div>clang: warning: CMakeFiles/main.dir/main.cpp.o: 'linker' input unused</div><div>clang: warning: CMakeFiles/main.dir/main_automoc.cpp.o: 'linker' input unused</div><div>clang: warning: /opt/Qt5.7.0/5.7/gcc_64/lib/libQt5Core.so.5.7.0: 'linker' input unused</div><div>clang: warning: -Wl,-rpath,/opt/Qt5.7.0/5.7/gcc_64/lib: 'linker' input unused</div><div>clang: warning: argument unused during compilation: '-rdynamic'</div><div>make[3]: Leaving directory '/mnt/e/_working/tidy/build/linux'</div></div><div>...</div><div><br></div><div><br></div><div><br></div><div>I modified the original cmake file to this:</div><div><br></div><div><div>SET(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} --analyze")</div><div><br></div><div>set_target_properties(main</div><div>    PROPERTIES</div><div>    CXX_STANDARD 14</div><div>    CXX_EXTENSIONS OFF</div><div>    AUTOMOC ON</div><div>    AUTOUIC ON</div><div>#    CXX_CLANG_TIDY</div><div>#        "clang-tidy"</div><div>#        "-checks=modernize-*,readability-*,performance-*"</div><div>#        "-fix"</div><div>)</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 6, 2016 at 11:59 AM, Artem Dergachev <span dir="ltr"><<a href="mailto:noqnoqneo@gmail.com" target="_blank">noqnoqneo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Whoops sorry missed this message!<br>
<br>
This is (or looks like) a false positive for the clang static analyzer's MallocChecker (clang-tidy runs the analyzer internally, but is not responsible for this checker directly).<br>
<br>
I think we should investigate that, and a preprocessed file with an -analyze/--analyze command line would speed us up significantly :)<span class=""><br>
<br>
On 12/5/16 9:26 PM, Tiago Macarios via cfe-dev wrote:<br>
</span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
Hi,<br>
<br>
If this is the wrong mail-list could someone point me to the correct one please?<br>
<br>
Mac<br>
<br></span><div><div class="h5">
On Thu, Dec 1, 2016 at 5:52 PM, Tiago Macarios <<a href="mailto:tiagomacarios@gmail.com" target="_blank">tiagomacarios@gmail.com</a> <mailto:<a href="mailto:tiagomacarios@gmail.com" target="_blank">tiagomacarios@gmail.co<wbr>m</a>>> wrote:<br>
<br>
    Hi,<br>
<br>
    First time poster so I hope I get the etiquette right.<br>
<br>
    I am trying to use clang-tidy (3.9.1) with a Qt (5.7) project and<br>
    I am getting a false positive memory leak.<br>
<br>
    Here is the CMake file:<br>
<br>
    cmake_minimum_required(VERSION 3.2)<br>
    project(main)<br>
    add_executable(main main.cpp)<br>
    set_target_properties(main<br>
        PROPERTIES<br>
        CXX_STANDARD 14<br>
        CXX_EXTENSIONS OFF<br>
        AUTOMOC ON<br>
        AUTOUIC ON<br>
        CXX_CLANG_TIDY<br>
            "clang-tidy"<br>
    "-checks=modernize-*,readabili<wbr>ty-*,performance-*"<br>
            "-fix"<br>
    )<br>
    find_package(Qt5Core)<br>
    target_link_libraries(main Qt5::Core)<br>
<br>
<br>
<br>
    Here is the main.cpp (it is the minimum amount of code to<br>
    reproduce the issue, the code itself is brain-dead):<br>
<br>
    #include <QObject><br>
<br>
    int main(int argc, char *argv[])<br>
    {<br>
        QObject a;<br>
    QObject::connect(&a, &QObject::destroyed, []() {});<br>
        return 0;<br>
    }<br>
<br>
<br>
<br>
    clang-tidy will display the following warning:<br>
<br>
    /opt/Qt5.7.0/5.7/gcc_64/includ<wbr>e/QtCore/qobject.h:343:16: warning:<br>
    Potential memory leak [clang-analyzer-cplusplus.NewD<wbr>eleteLeaks]<br>
            return connectImpl(sender, reinterpret_cast<void<br>
    **>(&signal), context, Q_NULLPTR,<br>
                   ^<br>
    /mnt/e/_Working/tidy/main.cpp:<wbr>8:5: note: Calling 'QObject::connect'<br>
    QObject::connect(&a, &QObject::destroyed, []() {});<br>
        ^<br>
    /opt/Qt5.7.0/5.7/gcc_64/includ<wbr>e/QtCore/qobject.h:293:16: note:<br>
    Calling 'QObject::connect'<br>
            return connect(sender, signal, sender, slot,<br>
    Qt::DirectConnection);<br>
                   ^<br>
    /opt/Qt5.7.0/5.7/gcc_64/includ<wbr>e/QtCore/qobject.h:308:39: note: '?'<br>
    condition is true<br>
            const int SlotArgumentCount = (FunctorArgumentCount >= 0)<br>
    ? FunctorArgumentCount : 0;<br>
                ^<br>
    /opt/Qt5.7.0/5.7/gcc_64/includ<wbr>e/QtCore/qobject.h:340:13: note:<br>
    Left side of '||' is false<br>
            if (type == Qt::QueuedConnection || type ==<br>
    Qt::BlockingQueuedConnection)<br>
                ^<br>
    /opt/Qt5.7.0/5.7/gcc_64/includ<wbr>e/QtCore/qobject.h:340:9: note:<br>
    Taking false branch<br>
            if (type == Qt::QueuedConnection || type ==<br>
    Qt::BlockingQueuedConnection)<br>
            ^<br>
    /opt/Qt5.7.0/5.7/gcc_64/includ<wbr>e/QtCore/qobject.h:344:28: note:<br>
    Memory is allocated<br>
     new QtPrivate::QFunctorSlotObject<<wbr>Func2, SlotArgumentCount,<br>
     ^<br>
    /opt/Qt5.7.0/5.7/gcc_64/includ<wbr>e/QtCore/qobject.h:343:16: note:<br>
    Potential memory leak<br>
            return connectImpl(sender, reinterpret_cast<void<br>
    **>(&signal), context, Q_NULLPTR,<br>
                   ^<br>
<br>
<br>
<br>
    Here is the code it refers to QtCore/qobject.h:343:<br>
<br>
    return connectImpl(sender, reinterpret_cast<void **>(&signal),<br>
    context, Q_NULLPTR,<br>
                       new QtPrivate::QFunctorSlotObject<<wbr>Func2,<br>
    SlotArgumentCount,<br>
    typename QtPrivate::List_Left<typename SignalType::Arguments,<br>
    SlotArgumentCount>::Value,<br>
    typename SignalType::ReturnType>(slot),<br>
                       type, types,<br>
    &SignalType::Object::staticMet<wbr>aObject);<br>
<br>
<br>
<br>
    The object created by that new, does get properly destroyed. This<br>
    seems to happen at tCore\qobject_impl.h:168:<br>
<br>
            static void impl(int which, QSlotObjectBase *this_,<br>
    QObject *r, void **a, bool *ret)<br>
            {<br>
                switch (which) {<br>
                case Destroy:<br>
                    delete static_cast<QFunctorSlotObject<wbr>*>(this_); //HERE<br>
                    break;<br>
                case Call:<br>
    FuncType::template call<Args,<br>
    R>(static_cast<QFunctorSlotObj<wbr>ect*>(this_)->function, r, a);<br>
                    break;<br>
                case Compare: // not implemented<br>
                case NumOperations:<br>
    Q_UNUSED(ret);<br>
                }<br>
            }<br>
<br>
<br>
<br>
    From a naive perspective it seems like that false positive leak<br>
    would be pretty hard to catch. So I guess the best solution (at<br>
    the moment) would be for me to silence the error. (Please someone<br>
    correct me if I am wrong).<br>
<br>
    Googling around I found two different ways to silence this false<br>
    positives:<br>
    // NOLINT<br>
    #ifndef __clang_analyzer__<br>
<br>
    I tried to use both in multiple ways, see this SO post:<br>
    <a href="http://stackoverflow.com/questions/40642307/silencing-clang-tidy" rel="noreferrer" target="_blank">http://stackoverflow.com/quest<wbr>ions/40642307/silencing-clang-<wbr>tidy</a><br>
    <<a href="http://stackoverflow.com/questions/40642307/silencing-clang-tidy" rel="noreferrer" target="_blank">http://stackoverflow.com/ques<wbr>tions/40642307/silencing-clang<wbr>-tidy</a>><br>
    But I still haven't figured out a way to silence this error. Maybe<br>
    someone can help me figure this one out?<br>
<br>
    FYI: QObject::connect is used all over Qt code. So I would rather<br>
    patch the Qt source files, then have to annotate every call to<br>
    that function.<br>
<br>
    Mac.<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br></div></div>
______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
</blockquote>
<br>
</blockquote></div><br></div>