-
Notifications
You must be signed in to change notification settings - Fork 13.6k
lambda expression is not a constant expression when auto (generic) parameter is used. #35052
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
This is still being rejected with post 17 trunk(cf7d4f5) I have simplified the code a bit. The code will compile fine if either the argument type of the lambda is specified, or the return type of the lambda is not specified. code
error
|
@llvm/issue-subscribers-clang-frontend Author: None (llvmbot)
| | |
| --- | --- |
| Bugzilla Link | [35704](https://llvm.org/bz35704) |
| Version | trunk |
| OS | Windows NT |
| Attachments | [sample cpp file](https://user-images.githubusercontent.com/60944935/143756747-1ebddae5-0c33-4886-ae99-12a8f1d0fed6.gz) |
| Reporter | LLVM Bugzilla Contributor |
Extended DescriptionWhen constexpr lambda used in constant expression it going non constant when its parameter is auto. In this sample got an error: 1> ConsoleApplication1.cpp(20,16): error : constexpr if condition is not a constant expression But if auto predicate = [](auto v) constexpr -> bool replaced by auto predicate = [](size_t v) constexpr -> bool all ok. #include <iostream> template<typename T> template<> template<typename T, typename F> int main()
} |
I wonder if this is related to: #71015 |
Reopen it as the PR has been reverted in #98991. |
Extended Description
When constexpr lambda used in constant expression it going non constant when its parameter is auto.
In this sample got an error:
1> ConsoleApplication1.cpp(20,16): error : constexpr if condition is not a constant expression
1> if constexpr (f(TypeTag::value))
1> ^~~~~~~~~~~~~~~~~~~~
But if
auto predicate = [](auto v) constexpr -> bool
replaced by
auto predicate = [](size_t v) constexpr -> bool
all ok.
#include
template
struct TypeTag
{
constexpr static size_t value = 1;
};
template<>
struct TypeTag
{
constexpr static size_t value = 2;
};
template<typename T, typename F>
constexpr auto func(F f)
{
if constexpr (f(TypeTag::value))
{
return int{1};
}
else
{
return float{2.2f};
}
}
int main()
{
auto predicate = [](auto v) constexpr -> bool // does not compile when v is auto
{
return v == 1;
};
}
The text was updated successfully, but these errors were encountered: