[llvm-bugs] [Bug 52099] False positive on -Wunused-lambda-capture if capturing a reference to a global variable

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Oct 6 12:15:47 PDT 2021


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

Richard Smith <richard-llvm at metafoo.co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #2 from Richard Smith <richard-llvm at metafoo.co.uk> ---
Clang is correct: this capture is not needed according to the rules of the C++
standard. See: https://godbolt.org/z/1h88Kf8dE

Because the reference is initialized by a constant expression, the use of the
reference is required by the C++ standard to (effectively) be rewritten to its
initializer, so the capture is unnecessary and will never actually be used.

In the case where the reference is initialized from a conditional expression,
the initializer is no longer a constant expression, so the rewrite doesn't
happen and a capture is required.

-- 
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/20211006/cc8953b3/attachment.html>


More information about the llvm-bugs mailing list