This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/44952] #include <iostream.h> imply global constructor.
- From: "pinskia at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 15 Jul 2010 16:30:23 -0000
- Subject: [Bug libstdc++/44952] #include <iostream.h> imply global constructor.
- References: <bug-44952-176@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #4 from pinskia at gcc dot gnu dot org 2010-07-15 16:30 -------
(In reply to comment #2)
> Why's this not in libstdc++.so .init?
because this will not work if libstdc++ is a static library.
Take:
#include <iostream>
namespace {
struct g
{
g(){ std::cout << "t"; }
};
g one;
}
--- CUT ---
The C++ standard says order of initializers between TUs is unspecified (though
the order inside TUs is specified as being the first one will run first).
So with a static version, the above will be included first and that will cause
std::cout to be used without being initialized.
>... and are we required to emit the constructor even if we know var is not
used?
It is hard to do that in Standard C++ really or imposable.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44952