This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
g++ -- can unused constructors affect generated code??
- From: Miles Bader <miles dot bader at necel dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 24 Jul 2006 11:26:02 +0900
- Subject: g++ -- can unused constructors affect generated code??
- Reply-to: Miles Bader <miles at gnu dot org>
[Sorry if this is a dup -- I earlier posted it via a newsreader, but
then later realized I have no idea if that newsgroup is gatewayed to the
mailing list or not.]
I have a fairly straight-forward "Color" class, which works pretty well.
Recently I added a new constructor for I/O purposes, and very oddly, it
seems to be making the generated code worse, even in places that most
certainly don't call the constructor.
Unfortunately I haven't been able to work out exactly what's going on,
but this is very confusing -- I though C++ constructors were essentially
"free" in the sense that if you didn't use them (including
accidentally), they could not affect code. Is this assumption not true?
Here's a basic snippet of the class (lots of hair omitted though); the
new constructor is the weird one with lots of args and "explicit" -- I
added all that to make damn sure it wasn't getting called by accident:
class Color
{
public:
typedef float component_t;
Color () : _r (0), _g (0), _b (0) { }
Color (component_t r, component_t g, component_t b)
: _r (r), _g (g), _b (b)
{ }
Color (int grey) : _r (grey), _g (grey), _b (grey) { }
Color (float grey) : _r (grey), _g (grey), _b (grey) { }
Color (double grey) : _r (grey), _g (grey), _b (grey) { }
// This is never used, but if I delete it, generated code changes!!
//
explicit Color (const float *tuple, const float *tuple2,
const float *tuple3, const float *tuple4,
const float *lots, const float *of, const float *crap)
: _r (tuple[0]), _g (tuple[1]), _b (tuple[2])
{ }
// ... methods (none virtual)
component_t _r, _g, _b;
};
As you can see the funny constructor is very basic.
If I comment out that constructor, then in an optimized build, the code
changes in funny ways -- I'm not sure what's going on, but in some cases
for instance, it seems to assume more registers are getting clobbered by
calls (sorry for the vagueness, I don't have a nice enough test case
that I want to post it here). In a non-optimized build, the difference
goes away.
I realize this isn't a good bug report, but I'm just searching for hints
to help me figure out what's going on...
Here's the version of g++ I'm using:
g++ (GCC) 4.1.2 20060715 (prerelease) (Debian 4.1.1-9)
Thanks,
-Miles
--
Suburbia: where they tear out the trees and then name streets after them.