I have this code:
constexpr int log2(const unsigned int x) {
return x < 4 ? 1 : 1 + log2(x / 2);
}
int main() {
bitset<log2(2)> foo;
int bar[log2(8)];
cout << log2(8) << endl;
}
This works fine in gcc: https://ideone.com/KooxoS
But when I try on visual-studio-2017 I get these errors:
error C2975:
_Bits
: invalid template argument forstd::bitset
, expected compile-time constant expression
note: see declaration of_Bits
error C2131: expression did not evaluate to a constant
note: failure was caused by call of undefined function or one not declaredconstexpr
note: see usage oflog2
Obviously log2
is constexpr
so I assume this is just a bug in visual-studio-2017. Is there a way I can work around this bug?