C++ template bugs in gcc 4.6
I've been working with gcc 4.6 with C++ doing some templates exercises I seem to have some unexplained behavior which might be a bug, or maybe I'm ignorant. First - let me give you a link for my code http://www.nylxs.com/docs/linklist.tgz gcc version ruben@www2:~> g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/i586-suse-linux/4.6/lto-wrapper Target: i586-suse-linux Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib --libexecdir=/usr/lib --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.6 --enable-ssp --disable-libssp --disable-plugin --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap --with-slibdir=/lib --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --program-suffix=-4.6 --enable-linux-futex --without-system-libunwind --with-plugin-ld=/usr/bin/gold --with-arch-32=i586 --with-tune=generic --build=i586-suse-linux Thread model: posix gcc version 4.6.0 20110415 [gcc-4_6-branch revision 172496] (SUSE Linux) specifically, I wrote a program to test my templates that create a linked list class. There is a simple library to do some statistics on the list members. It is doing a double delete core dump in a section of code that I see no reason for a destructor call. It didn't do this for a simpler version of the template argument call. ddd ./test_del2 test_del2.cpp:84 79 for( i=0; i < 100; ++i){ 80 std::cout << "index " << i << "--- \n"; 81 tally = new chainlist::List >; 82 stats::take_tally(a[i], tally ); 83 std::cout << "Creating Tally " << std::endl; 84 tallies->insert(*tally); 85 std::cout << "inserted population figures for index " << i << "---\n"; 86 delete tally; 87 88 //visual inspection of population data to make sure the resiults work 89 // std::cout << "visual inspection of population data to make sure the results work" << std::endl; breaking on line 84 and the stepping through 263 void List::insert ( T val ) 264 { 265 if(!front()){ 266 Node * tmp = new Node(val); 267 front(tmp); 268 endd(tmp); 269 cursor(tmp); 270 sizeup(); 271 return; 272 }else{ 273 Node * tmp = new Node(val, endd()); 274 // endd()->next(tmp); // redundant 275 endd(tmp); 276 cursor(tmp); 277 sizeup(); 278 return; 279 } 280 } /* --- end of method List::insert /home/ruben/cplus/link_list_template_mysql/linklist.h:265 is the next line on line 266 is where it seems to be doing weird stuff home/ruben/cplus/link_list_template_mysql/linklist.h:266 it calls the correct constructor for the node object /home/ruben/cplus/link_list_template_mysql/linklist.h:82 81 Node::Node(unk val, Node *item_to_link_to){ 82 value(val); 83 if(!item_to_link_to){ 84 next_ = 0; 85 } 86 87 else{ 88 next(item_to_link_to->next()); 89 item_to_link_to->next(this); 90 } 91 } I the calls the accessory method value() from the list class 108 } 109 110 template 111 void Node::value(unk val){ 112 value_ = new unk(val); 113 } 114 /home/ruben/cplus/link_list_template_mysql/linklist.h:112 it returns nomally 81 Node::Node(unk val, Node *item_to_link_to){ 82 value(val); 83 if(!item_to_link_to){ 84 next_ = 0; 85 } 86 87 else{ 88 next(item_to_link_to->next()); 89 item_to_link_to->next(this); 90 } 91 } 92 chainlist::Node > >::Node (this=0x809f488, val=..., item_to_link_to=0x0) at /home/ruben/cplus/link_list_template_mysql/linklist.h:83 then it calls for the List destructor, I have no idea way 373 template 374 List::~List(){ 375 remove_all(); 376 // std::cout << "Deleted All*" << __LINE__ << std::endl; 377 } 378 (gdb) ptype List Type chainlist::List > has no component named List. (gdb) *** glibc detected *** /home/ruben/cplus/link_list_template_mysql/test_del2: double free or corruption (out): 0x0809f460 *** === Backtrace: = /lib/libc.so.6[0xb7d9150b] /lib/libc.so.6[0xb7d92de4] /lib/libc.so.6(cfree+0x6d)[0xb7d95fdd] /usr/lib/libstdc++.so.6(_ZdlPv+0x1f)[0xb7f7c87f] /home/ruben/cplus/link_list_template_mysql/test_del2[0x804b4a4] /home/ruben/cplus/link_list_template_mysql/test_del2[0x804b2c6] /home/ruben/cplus/link_list_template_mysql/test_del2[0x804aa30] /home/ruben/cplus/link_list_template_mysql/test_del2[0x804987d] /home/ruben/cplus/link_list_template_mysql/test_del2[0x80498f0] /home/ruben/cplus/link_list_template_mysql/test_del2[0x8048d42] /lib/libc.so.6(__libc_start_main+0xfe)[0xb7d3aace] /home/ruben/cplus/link_list_template_mysql/test_del2[0x8048961] === Memory map: 08048000-0804d000 r-xp 08:12 270203586 /home/ruben/cplus/link_list_template_mysql/test_del2 0804d000-0804e000 r--p 4000 08:12 270203586 /home/ruben/cplus/link_list_template_mysql/test_del2 0804e000-0804f000 rw-p 5000 08:12 270203586 /home/ruben/cplus/link_list_template_mysql/te
Re: C++ template bugs in gcc 4.6
On Sun, May 22, 2011 at 02:29:08PM +0100, Jonathan Wakely wrote: > re http://gcc.gnu.org/ml/gcc-bugs/2011-05/msg01899.html > > The gcc-bugs mailing list is for mails automatically generated by > bugzilla, if you want to report a bug please do so in bugzilla, not by > email. See http://gcc.gnu.org/bugs/ for instructions. > > If you want to ask for help using g++ then use the gcc-help mailing > list, see http://gcc.gnu.org/lists.html > Can't be done. It's not working, aside from the fact that this is too complex of an example to fit within the parameters. I spent nearly 45 minutes gathering all the information together. If the post is not adequate, that is fine. That's why i don't report bugs. > Thanks. -- http://www.mrbrklyn.com - Interesting Stuff http://www.nylxs.com - Leadership Development in Free Software So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world - RI Safir 1998 http://fairuse.nylxs.com DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002 "Yeah - I write Free Software...so SUE ME" "The tremendous problem we face is that we are becoming sharecroppers to our own cultural heritage -- we need the ability to participate in our own society." "> I'm an engineer. I choose the best tool for the job, politics be damned.< You must be a stupid engineer then, because politcs and technology have been attached at the hip since the 1st dynasty in Ancient Egypt. I guess you missed that one." © Copyright for the Digital Millennium
Re: C++ template bugs in gcc 4.6
On Sun, May 22, 2011 at 03:24:11PM +0100, Jonathan Wakely wrote: > On 22 May 2011 15:16, Ruben Safir wrote: > > On Sun, May 22, 2011 at 02:29:08PM +0100, Jonathan Wakely wrote: > >> re http://gcc.gnu.org/ml/gcc-bugs/2011-05/msg01899.html > >> > >> The gcc-bugs mailing list is for mails automatically generated by > >> bugzilla, if you want to report a bug please do so in bugzilla, not by > >> email. See http://gcc.gnu.org/bugs/ for instructions. > >> > >> If you want to ask for help using g++ then use the gcc-help mailing > >> list, see http://gcc.gnu.org/lists.html > >> > > > > > > Can't be done. It's not working, aside from the fact that this is too > > complex of an example to fit within the parameters. > > It's working fine for me. > well it doesn't for me. seens to not like my email address. > As for too complex: nonsense. Did you bother to read the link I provided? not interested in argueing...have other things I need to do. I'm sorry I made the report now. Easier to just code around the bug. Thanks for your time. > You can attach preprocessed source, though you should really try to > reduce it to a minimal testcase - I don't believe mysql++ is really > necessary to demonstrate the problem. > > None of that changes the fact gcc-bugs is the wrong list. > > > I spent nearly 45 minutes gathering all the information together. If > > the post is not adequate, that is fine. That's why i don't report bugs. > > Run your code under valgrind, it shows you were the first memory > corruption occurs. doing that, thanks > > If you don't want to report bugs then dont' be surprised if they don't > get fixed. nothing surprises me anymore...in more ways then most people can comprehend... The world sucks. Ruben -- http://www.mrbrklyn.com - Interesting Stuff http://www.nylxs.com - Leadership Development in Free Software So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world - RI Safir 1998 http://fairuse.nylxs.com DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002 "Yeah - I write Free Software...so SUE ME" "The tremendous problem we face is that we are becoming sharecroppers to our own cultural heritage -- we need the ability to participate in our own society." "> I'm an engineer. I choose the best tool for the job, politics be damned.< You must be a stupid engineer then, because politcs and technology have been attached at the hip since the 1st dynasty in Ancient Egypt. I guess you missed that one." © Copyright for the Digital Millennium