-
Notifications
You must be signed in to change notification settings - Fork 13.2k
constexpr value in a lambda #26001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Sorry about the delayed attention - I became aware of this bug just earlier today. Patch submitted for review : https://reviews.llvm.org/D31588 |
This issue was only partially fixed. //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 |
A patch to address this bug is under review: https://reviews.llvm.org/D92733 |
@llvm/issue-subscribers-clang-frontend |
No longer crashes but behavior still incorrect for the template case |
Extended Description
If I am correct the following code should be valid c++14:
However, clang does not compile this code.
It does compile with when capturing [=], [i] or [&].
It also compiles if the i is made static.
This is related to a stackoverflow-question:
http://stackoverflow.com/questions/33873788/how-can-i-use-a-constexpr-value-in-a-lambda
clang version:
Debian clang version 3.8.0-svn247818-1~exp1 (trunk) (based on LLVM 3.8.0)
compile command:
The text was updated successfully, but these errors were encountered: