This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/33016] type_info::before() will not return the same value
- From: "bangerth at dealii dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 8 Sep 2007 23:43:10 -0000
- Subject: [Bug libstdc++/33016] type_info::before() will not return the same value
- References: <bug-33016-14951@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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