[llvm-bugs] [Bug 25627] constexpr value in a lambda

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Dec 9 07:58:10 PST 2019


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

Bastien Penavayre <bastienPenava at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |---
                 CC|                            |bastienPenava at gmail.com

--- Comment #3 from Bastien Penavayre <bastienPenava at gmail.com> ---
This issue was only partially fixed.
The same code in a template context won't compile:

//works
void f0()
{
   constexpr int i = 0;
   []{ return i; };
}

//error
template<class T>
void f1()
{
   constexpr int i = 0;
   []{ return i; }; //i cannot be implicitly captured ...
}

godbolt link: https://godbolt.org/z/3Sc46U

console output:

<source>:5:4: warning: expression result unused [-Wunused-value]

   []{ return i; };

   ^~~~~~~~~~~~~~~

<source>:13:15: error: variable 'i' cannot be implicitly captured in a lambda
with no capture-default specified

   []{ return i; };

              ^

<source>:12:18: note: 'i' declared here

   constexpr int i = 0;

                 ^

<source>:13:4: note: lambda expression begins here

   []{ return i; };

   ^

1 warning and 1 error generated.

Compiler returned: 1

-- 
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/20191209/4f999093/attachment.html>


More information about the llvm-bugs mailing list