[cfe-dev] [clang-tidy] Issues with C++17 structured bindings

Tamir Zahavi-Brunner via cfe-dev cfe-dev at lists.llvm.org
Tue Jul 6 04:25:24 PDT 2021


Hello,

Using clang-tidy-12, I'm getting false warnings when using structured
bindings. There can actually be a variety of issues, but here is a very
small example I've narrowed it down to:

auto [ptr, num] = std::make_tuple(malloc(1), 1);
free(ptr);

For which I get the following warning:

/tmp/test.cpp:7:5: warning: Potential leak of memory pointed to by
'._M_head_impl' [clang-analyzer-unix.Malloc]
    free(ptr);
    ^
/tmp/test.cpp:6:39: note: Memory is allocated
    auto [ptr, num] = std::make_tuple(malloc(1), 1);
                                      ^
/tmp/test.cpp:7:5: note: Potential leak of memory pointed to by
'._M_head_impl'
    free(ptr);
    ^

Searching online, I saw that I'm not the first person to encounter such
issues (
https://stackoverflow.com/questions/62706928/clang-tidy-vs-structured-bindings)
but I couldn't find any solution.

Is this a bug in clang-tidy or am I missing something? Is there anything I
can do to solve this other than stopping using structured bindings?

Thanks,
Tamir
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20210706/3cadebfb/attachment-0001.html>


More information about the cfe-dev mailing list