[variant]crtp variant seems to create 2 variants when only 1 needed.

The attached code attempts to use CRTP (Curiously Recurring Template Pattern) to see if recursive_variant can be avoided; however, I'm getting 2 variant's produced instead of 1 and the which gives the wrong result. The output is: <-- cut here -- /home/evansl/prog_dev/boost-svn/ro/boost-trunk/sandbox/build/gcc4_1/lje/libs/variant/test/crtp_test.exe set_of_objects_tracked+ ===>Enter:int_list_1 scope object_tracked+:id=1:default ===>Enter:variant() /home/evansl/prog_dev/boost-svn/ro/boost-trunk/sandbox/lje/libs/variant/test/variant.hpp:1176:id=1 ===>Exit:variant() object_tracked+:id=2:default ===>Enter:template<typename T>variant(T& operand) /home/evansl/prog_dev/boost-svn/ro/boost-trunk/sandbox/lje/libs/variant/test/variant.hpp:1360:id=2 ===>Enter:template<typename T>convert_construct(T& operand,int,false) /home/evansl/prog_dev/boost-svn/ro/boost-trunk/sandbox/lje/libs/variant/test/variant.hpp:1268 /home/evansl/prog_dev/boost-svn/ro/boost-trunk/sandbox/lje/libs/variant/test/initializer.hpp:95:index=1 /home/evansl/prog_dev/boost-svn/ro/boost-trunk/sandbox/lje/libs/variant/test/variant.hpp:1280:after initialize:which=1 ===>Exit:template<typename T>convert_construct(T& operand,int,false) /home/evansl/prog_dev/boost-svn/ro/boost-trunk/sandbox/lje/libs/variant/test/variant.hpp:1362:after_convert_construct:which=1 ===>Exit:template<typename T>variant(T& operand) ===>Enter:template<class T>vlist(T) id=1 T.first=1 this->which=0 ===>Exit:template<class T>vlist(T) int_list_1.which()=0 object_tracked-:id=2:am_i_live=1 object_tracked-:id=1:am_i_live=1 ===>Exit:int_list_1 scope set_of_objects_tracked-
-- cut here -- The output produced from just the attached includes:
this->which=0 but I expected which=1 since the CTOR arg is the 2nd bounded type: (pair<int,list_type*>). The other output's are produced by making object_tracked a super of variant and also putting debug prints in various CTOR's. The output: ===>Enter:variant() /home/evansl/prog_dev/boost-svn/ro/boost-trunk/sandbox/lje/libs/variant/test/variant.hpp:1176:id=1 ===>Exit:variant() indicates a variant produced with the default CTOR has id=1 which is the id of the vlist produced with the pair CTOR arg. Does anyone have any clue why this is happening, IOW why which=0 instead of 1. I tried using the debugger, but it was not more help. TIA. -regards, Larry

On 01/25/08 23:07, Larry Evans wrote:
The attached code attempts to use CRTP (Curiously Recurring Template Pattern) to see if recursive_variant can be avoided; however, I'm getting 2 variant's produced instead of 1 and the which gives the wrong result.
The attached code has test_list(void) and test_variant(void). The former has variant as super, the latter just uses a variant. The former gets wrong results, the latter correct results. There must be a compiler bug, AFAICT. I'm using g++4.1 on linux created with uguntu-7.10-desktop-amd64.iso. g++-4.1 -v Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.1.3 --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --enable-checking=release x86_64-linux-gnu Thread model: posix gcc version 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2) Anyone else having similar problems?

On 01/26/08 22:46, Larry Evans wrote: [snip]
The attached code has test_list(void) and test_variant(void). The former has variant as super, the latter just uses a variant. The former gets wrong results, the latter correct results.
[snip] In an attempt to make the code more easily ported, I defined some macros to disable my personal debugging tools. As a result, the wrong which() value no longer appears! Sorry for noise (I think, although I still can't figure out what I did to cause the bad result).

On 01/27/08 00:02, Larry Evans wrote: [snip]
Sorry for noise (I think, although I still can't figure out what I did to cause the bad result).
I left off the typedef keyword in the vlist::super_type decl :( Very embarrassing.
participants (1)
-
Larry Evans