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

via cfe-dev cfe-dev at lists.llvm.org
Wed Jul 28 08:18:06 PDT 2021


I still failed to reproduce this on 424fe903d4d4b0f52bd4f86f62587efa6561d251 Fri Jul 23 12:51:37.

 

Please file a ticket on the official Bugzilla tracker about this if you have the necessary information/reproducer.

Try dumping the preprocessed file, that might be different on my system.

 

Balazs

 

From: Tamir Zahavi-Brunner <tamir.z3 at gmail.com> 
Sent: 2021. július 28., szerda 10:30
To: Benics Balázs <benicsbalazs at gmail.com>
Cc: cfe-dev at lists.llvm.org
Subject: Re: [cfe-dev] [clang-tidy] Issues with C++17 structured bindings

 

The full contents of the file are:

 

#include <malloc.h>
#include <tuple>

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

    return 0;
}

 

And the line I run which gives me the above errors is:

 

clang-tidy test.cpp -- --std=c++17

 

On Wed, Jul 28, 2021 at 11:06 AM Benics Balázs <benicsbalazs at gmail.com <mailto:benicsbalazs at gmail.com> > wrote:

Hi,

It seems like its a Clang Static Analyzer checker warns about something.

 

Could you please send the complete reproducer?

I failed reproducing this.

 

Regards,

Balazs

 

 

  _____  

From: cfe-dev <cfe-dev-bounces at lists.llvm.org <mailto:cfe-dev-bounces at lists.llvm.org> > on behalf of Tamir Zahavi-Brunner via cfe-dev <cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org> >
Sent: Tuesday, July 6, 2021 1:25:12 PM
To: cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>  <cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org> >
Subject: [cfe-dev] [clang-tidy] Issues with C++17 structured bindings 

 

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/20210728/912cea16/attachment.html>


More information about the cfe-dev mailing list