[cfe-dev] Question regarding -Wlifetime

Gábor Horváth via cfe-dev cfe-dev at lists.llvm.org
Sat Oct 5 02:22:44 PDT 2019


Hi Paulo,

The -Wlifetime analysis is not part of mainline clang yet (only the
statement-local warnings). If you have some questions, concerns regarding
the flow-sensitive analysis feel free to open a ticket at
https://github.com/mgehre/llvm-project

Currently, the flow-sensitive lifetime analysis does not check for memory
leaks. If you want to find leaks statically, you could try out the Clang
Static Analyzer (https://clang-analyzer.llvm.org/) which has some great
checks to find such issues.

Cheers,
Gabor

On Sat, 5 Oct 2019 at 11:10, Paulo Pinto via cfe-dev <cfe-dev at lists.llvm.org>
wrote:

> Hi everyone,
>
> just decided to start playing around with -Wlifetime on Godbolt, and came
> up with
> an example that failed to meet my expectations, namely:
> char *leak()
> {
>    return new char;
> }
>
> int main()
> {
>     char *ch = leak();
> }
>
> Shouldn't the lifetime static analyser complain that ch on main() leaks,
> or am I expecting too much from the analyser?
>
> Initially I though that by using main(), the analyser just assumed it
> would be released anyway, but renaming it to something
> else, still doesn't trigger a leak warning.
>
> Thanks in advance,
> Paulo
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20191005/158d5ce2/attachment.html>


More information about the cfe-dev mailing list