------- Comment #4 from bangerth at dealii dot org 2007-09-08 23:43 ------- I have to admit that the result is strange. However, it appears entirely within the compiler's right to do this, as [18.5.1/5] says: ------------- bool before(const type_info& rhs) const;
5 Effects: Compares the current object with rhs. 6 Returns: true if *this precedes rhs in the implementation's collation order. ------------- So the result is compiler defined. In reality what happens is this: the before() compares two addresses in memory that depend on the time at which the compiler emitted the typeinfo data. This in turn depends on which class's typeinfo first needed to be emitted. This can be seen using this little program: -------------------- #include "stdio.h" #include "typeinfo" class A {}; class B {}; int main(void) { #ifdef XX printf("typeid(B).name(): %s\n", typeid(B).name()); printf("typeid(A).name(): %s\n", typeid(A).name()); #else printf("typeid(A).name(): %s\n", typeid(A).name()); printf("typeid(B).name(): %s\n", typeid(B).name()); #endif printf("A is before B: %d\n", typeid(A).before(typeid(B))); return 0; } ----------------- Depending on whether XX is set or not, the result of before() is either true or false. But as explained above, this is entirely within the implementation's discretion. W. -- bangerth at dealii dot org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bangerth at dealii dot org Status|UNCONFIRMED |RESOLVED Component|c++ |libstdc++ Resolution| |INVALID http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33016