-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[clang++] constexpr is not propagated in lambda in a template context under specific condition #94849
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
Labels
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
constexpr
Anything related to constant evaluation
duplicate
Resolved as duplicate
lambda
C++11 lambda expressions
Comments
@llvm/issue-subscribers-clang-frontend Author: Stephen Haoqian Xu (stephen-hqxu)
I initially discovered this issue on the official clang 18 build on Ubuntu. Then I did a quick test on [compiler explorer](https://godbolt.org/), and it seems to affect all clang versions (starting clang 5) that support C++17 constexpr lambda feature; perhaps platform does not really matter.
Consider the following code: template<typename = void>
void doStuff() {
auto equalsOne = [](auto x) -> bool {
return x == 1;
};
static_assert(equalsOne(1), "oops");
}
int main() {
doStuff();
} And compile with: clang++ -std=c++17 ./example.cpp -o example This code does not compile and will generate the following errors: There are a few observations:
|
Duplicate of #35052 |
zyn0217
added a commit
that referenced
this issue
Jun 16, 2024
We had a code path in `Sema::MarkFunctionReferenced()` that deferred local lambda instantiation even for constexprs. This resulted in any calls to them referring to function decls that lack bodies and hence failures at constant evaluation. The issue doesn't occur when the lambda has no explicit return type because the return type deduction requires instantiation. Fixes #35052 Fixes #94849
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
constexpr
Anything related to constant evaluation
duplicate
Resolved as duplicate
lambda
C++11 lambda expressions
I initially discovered this issue on the official clang 18 build on Ubuntu. Then I did a quick test on compiler explorer, and it seems to affect all clang versions (starting clang 5) that support C++17 constexpr lambda feature; perhaps platform does not really matter.
Consider the following code:
And compile with:
This code does not compile and will generate the following errors:
There are a few observations:
doStuff
non-template, i.e. removingtemplate<typename = void>
, compiles.auto x
toint x
, compiles. However, it still does not compile if it is in C++20 and replaceauto
with explicit lambda template parameter. This basically means it does not compile when lambda is a template, regardless of how it is templated.-> bool
to-> auto
, or equivalently removing the trailing return type, compiles.constexpr
, i.e.[](auto x) constexpr -> bool
.The text was updated successfully, but these errors were encountered: