L
Luke Meyers
I just spent two and a half days chasing down a bug resulting from
initializing a reference to itself, like so:
struct Bar;
struct Foo {
Bar& bar;
Foo() : bar(bar) {}
};
The compiler I was using (gcc 3.2.3) issued no warning for this. I
assume that any use of bar produces undefined behavior. If this is the
case, then it seems to be a defect in the compiler not to issue a
warning. Is my analysis correct? Specifically:
(1) Is there any conceivable circumstance in which this will produce
anything but undefined behavior?
(2) is there any reason why a compiler would have difficulty detecting
this, in the general case?
(3) Anyone happen to know if later versions of gcc, or other compilers,
address this?
Please note that while I'm referring to a specific compiler here, my
question (at least, part (1)) is really about language behavior, hence
not (IMHO) OT.
Luke
initializing a reference to itself, like so:
struct Bar;
struct Foo {
Bar& bar;
Foo() : bar(bar) {}
};
The compiler I was using (gcc 3.2.3) issued no warning for this. I
assume that any use of bar produces undefined behavior. If this is the
case, then it seems to be a defect in the compiler not to issue a
warning. Is my analysis correct? Specifically:
(1) Is there any conceivable circumstance in which this will produce
anything but undefined behavior?
(2) is there any reason why a compiler would have difficulty detecting
this, in the general case?
(3) Anyone happen to know if later versions of gcc, or other compilers,
address this?
Please note that while I'm referring to a specific compiler here, my
question (at least, part (1)) is really about language behavior, hence
not (IMHO) OT.
Luke