--- Begin Message ---
Package: g++-4.3
Version: 4.3.2-1.1
Severity: important
Let an example do the talking
template< unsigned int result, unsigned int wanted, unsigned int guess >
struct log2_calculator;
// Specialisation that ends recursion.
template< unsigned int result, unsigned int wanted >
struct log2_calculator< result, wanted, 0>
{
enum { value = 0 }; // Invalid.
};
template< unsigned int result, unsigned int wanted, unsigned int guess >
struct log2_calculator
{
typedef log2_calculator< result+1, wanted, guess << 1 > next_value_type;
/*HERE*/enum { value = (wanted <= guess) ? result : next_value_type::value };
};
The intention of this code is to work out log2(a) at compile time, lacking
some other mechanism.
This allows...
enum { is3 = log2_calculator< 0, 8, 1 >::value };
enum { is4 = log2_calculator< 0, 16, 1 >::value };
enum { is6 = log2_calculator< 0, 64, 1 >::value };
....something that's more obviously useful inside templates.
enum { isX = log2_calculator< 0, sizeof(N)*8, 1 >::value };
Anyway, the problem becomes obvious when you omit the specialisation from the
above - g++ reaches it's template nesting limit because it's instantiating
the template that's the second value to "?" even though the conditional is
true.
I've marked the line above with /*HERE*/.
-- System Information:
Debian Release: 5.0.2
APT prefers stable
APT policy: (500, 'stable')
Architecture: amd64 (x86_64)
Kernel: Linux 2.6.26-2-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_IE.UTF-8, LC_CTYPE=en_IE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages g++-4.3 depends on:
ii gcc-4.3 4.3.2-1.1 The GNU C compiler
ii gcc-4.3-base 4.3.2-1.1 The GNU Compiler Collection (base
ii libc6 2.7-18 GNU C Library: Shared libraries
ii libgmp3c2 2:4.2.2+dfsg-3 Multiprecision arithmetic library
ii libmpfr1ldbl 2.3.1.dfsg.1-2 multiple precision floating-point
ii libstdc++6-4.3-dev 4.3.2-1.1 The GNU Standard C++ Library v3 (d
g++-4.3 recommends no packages.
Versions of packages g++-4.3 suggests:
ii g++-4.3-multilib 4.3.2-1.1 The GNU C++ compiler (multilib fil
ii gcc-4.3-doc 4.3.2.nf1-1 documentation for the GNU compiler
pn libstdc++6-4.3-dbg <none> (no description available)
-- no debconf information
--- End Message ---