This very simple code code gives an error in GCC 6.0:
template<class T>
struct S {
// error: cannot convert 'T' to 'const int' in initialization
static const int b = T{};
};
int main() {
}
Strangely, if I use regular braces instead (T()
) then the code compiles. Is this a bug? The code compiles fine in clang.
The reason that T()
works is because the compiler interprets it as a function declaration which takes no argument. The compiling would be done with just an explicit casting:
static const int b = (const int) T{};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With