This compiles
void f() {
constexpr bool x{};
auto g = []{
if constexpr (x) {
}
};
g();
}
int main () {
f();
}
and it compiles even if I change [] to [x] or to [&x]. In these two latter cases, though, clangd tells me
Lambda capture 'x' is not required to be captured for this use (fix available) [-Wunused-lambda-capture]
A first minor question would be: is capturing x in this case simply redundant? Or there's more?
But my main question is: from where in the standard should I understand that I can make without any capture in the case above? After all, just writing (void)x; before the if constexpr, for instance, makes the capture ([x] or [&x]) necessary.