I wonder why I can't use the [[maybe_unused]] attribute in the capture list of a lambda. Is there a reason that variables of a captured lists can't be marked as [[maybe_unused]]? This would avoid to capture all variables, means [&], in cases like this:
auto lambda = [&x, [[maybe_unused]] &y](){
if constexpr( x >= 0) {
return x;
}
else {
return y;
}
}
In each case where x >= 0 there is a compiler warning that y is not used. But if x < 0, there is no warning. My first try was to use [[maybe_unused]], but that is not possible.
My question: is there a reason, why I can't use the [[maybe_unused]] attribute in the capture list of lambda?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…