Recursive template instantiation error--help!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Building with:

g++-4.6.real (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1

This program:

template<unsigned int v>
class testit{
public:
    static const unsigned int width =
        ( v==0 ? 0 : testit<v >> 1>::width + 1);
};

int
main()
{
    unsigned int foo=testit<3>::width;
}

Errors out with complaint of exceeding maximum template instantiation
depth (error below) even though it seems it should compile like:

testit<3>
   3==0?  No, so width = testit <3 >> 1>::width + 1 ( which would be 1 + 1)
   testit<1>
       1==0? No, so width = testit<1 >> 1>::width+1 (which would be 0 + 1)
       testit<0>
       0==0 so width=0

Here's the error:

g++  -o testit testit.cpp
testit.cpp:5:40: error: template instantiation depth exceeds maximum of
1024 (use -ftemplate-depth= to increase the maximum) instantiating
‘testit<0u>::width’
testit.cpp:5:40:   recursively instantiated from ‘const unsigned int
testit<1u>::width’
testit.cpp:5:40:   instantiated from ‘const unsigned int testit<3u>::width’
testit.cpp:11:33:   instantiated from here

testit.cpp:5:40: error: template instantiation depth exceeds maximum of
1024 (use -ftemplate-depth= to increase the maximum) instantiating
‘testit<0u>::width’
testit.cpp:5:40:   recursively instantiated from ‘const unsigned int
testit<1u>::width’
testit.cpp:5:40:   instantiated from ‘const unsigned int testit<3u>::width’
testit.cpp:11:33:   instantiated from here

I also don't understand why I get the exact same sequence of errors twice.

Help!!! (and thanks;)

Patrick


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux