Reputation: 10480
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.
Upvotes: 10
Views: 310
Reputation: 1634
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{};
Upvotes: 2