I have come across a small (easily solvable though) problem while writing valid C++03 template code, which compiles normally, that will not compile when using the C++11 dialect.
The problem arises at the template parameter resolution. Let this code be an example of this:
template <uint32_t number>
struct number_of_bits {
enum {
value = 1 + number_of_bits<number >> 1>::value
};
};
template <>
struct number_of_bits<0> {
enum {
value = 0
};
};
Since C++11 allows now ">>" to finish a template parameter list that takes a templated parameter as the last argument, it creates a problem when parsing this code.
I am using GCC (version 4.8.1) as my compiler, and it compiles normally using the command line:
g++ test.cc -o test
But it fails to compile when I add the -std=c++11
command line switch:
g++ -std=c++11 test.cc -o test
Is this a C++11 language feature or is it a bug in GCC? is this a known bug if it's the case?
>>
necessarily closes 0 template arguments in C++03 but closes 2 template arguments in C++11. I am not sure how you would close the 2 unclosed arguments in C++03 without causing a compile failure on C++11. – Rolfe