[llvm-bugs] [Bug 50003] Warns about lambda function based on the return type that is not what inferred return type is

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Apr 16 12:40:33 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=50003

David Blaikie <dblaikie at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
                 CC|                            |dblaikie at gmail.com
             Status|NEW                         |RESOLVED

--- Comment #1 from David Blaikie <dblaikie at gmail.com> ---
Converting the lambda to a std::function doesn't change the type of the lambda.
The return type of the lambda is inferred by the type of the return statement
only.

Essentially the lambda this code creates is this:

auto unmentionable() {
  char t[10] = "abc";
  return t;
}
...
std::function<std::string()> f = unmentionable;

which results in a std::function that does something like this:

std::string func() {
  return unmentionable();
}

Because a char* is convertible to std::string, this ^ code compiles, but does
have the bug the diagnostic warns about - dangling pointer to a local variable.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210416/6b7667ce/attachment.html>


More information about the llvm-bugs mailing list