On Tue, 15 Dec 2009, Rahul Sampath wrote: > According to GCC 4.3.2, clearing an empty container is not safe:
Interesting. Apparently someone noticed this flaw in the C++ standard in 1999, but it wasn't officially fixed in the standard until 2003: http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#151 Looks like in the C++98 standard, clear() was still defined as erase(begin(), end()), but the standard for erase(q1,q2) said that q1 had to be a dereferenceable iterator. The resolution (to merely require that [q1, q2) be a valid, which includes empty, range) is in "Technical Corrigendum 1", which came out in 2003. gcc started adding support for c++0x draft features in the 4.3 series; I'm surpised they hadn't finished TC1 support yet! If 4.3.2 is actually segfaulting then we definitely want to fix it. But I hate adding an extra if(!empty()) test for people whose compilers are up to date. I'll wrap everything in an inline libmesh_clear() function, to make re-optimizing easier later; eventually it would be nice to detect compiler versions that support empty.clear() and automatically get rid of the redundant if(). Thanks for catching this! --- Roy ------------------------------------------------------------------------------ This SF.Net email is sponsored by the Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers http://p.sf.net/sfu/verizon-dev2dev _______________________________________________ Libmesh-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/libmesh-users
