The following C++ program aims to calculate the sum of some ints at compile time: //BEGINS SUM.CPP template<int N> class Sum { public: enum { val = N }; template<int K> class Inc : public Sum<val + K> { }; }; int main() { return(Sum<2>::Inc<3>::Inc<6>::Inc<4>::val); } //ENDS SUM.CPP Now GCC produces: $ g++ sum.c $ ./a.out ; echo $? 6 More generally, every Sum<x_0>::Inc<x_1>::Inc<x_2>::...::Inc<x_n>::val is always expanded to just x_0 + x_n. When compiled with Digital Mars C++ the same example produces 15 as output (more generally, produces the sum of all the provided integers as I would expect). Which is the right behaviour? --- $ g++ -v Using built-in specs. Target: x86_64-unknown-linux-gnu Configured with: ./gcc-4.3.3/configure Thread model: posix gcc version 4.3.3 (GCC) I checked this example against a barebone, fresh 4.3.3 build with just gcc-core and gcc-g++, gmp-4.2.1 and mpfr-2.3.0, all downloaded from a gcc mirror, fully boostrapped with no options on a Gentoo distribuition. The same behaviour occurs with a 4.1.2 GCC version on Gentoo and with a 3.4.4 GCC version on Cygwin. The Digital Mars C++ compiler version I used is 8.50 for win32.
Created attachment 17643 [details] the example program
The issue comes down to how is Inc injected into Inc. I can't remember the exact rules but I think GCC's behavior is correct.
For the record, the Intel compiler - which I trust much more than DM, sorry - behaves the same as GCC. I strongly believe GCC is correct. I even think we have something closed about this issue, let me see if I find it...
This is even rejected now.