Closed as not planned
Closed as not planned
Description
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:
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:
static assertion expression is not an integral constant expression
static_assert(equalsOne(1), "oops");
There are a few observations:
- The code compiles on GCC and MSVC.
- Make
doStuff
non-template, i.e. removingtemplate<typename = void>
, compiles. - Change the lambda call signature from
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. - Change the trailing return type of lambda
-> bool
to-> auto
, or equivalently removing the trailing return type, compiles. - It does not compile even if decorating the lambda with
constexpr
, i.e.[](auto x) constexpr -> bool
.