public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/24157] New: g++ allows variable to be initialized by value of variable being initialized
@ 2005-10-01 6:58 gahs at phys dot ksu dot edu
2005-10-01 15:40 ` [Bug c++/24157] " pinskia at gcc dot gnu dot org
0 siblings, 1 reply; 2+ messages in thread
From: gahs at phys dot ksu dot edu @ 2005-10-01 6:58 UTC (permalink / raw)
To: gcc-bugs
I found by pure accident that g++ allows the RHS of an initialization to be the
very variable that is being initialized. Two minimalist examples are given
below. The same behavior is present under gcc 2.95.2, 3.3.3, and 3.4.1.
I'm suprised that the new variable is even considered to be defined in the
context of the RHS of its own initializer, although I suppose it is concievable
in this mad mad world that it might be valid syntax under the standard. But
surely the compiler should at least issue the "warning: ... might be used
uninitialized" message when compiled with -O -W -Wall, since the variable is
definitely not initialized yet!
Example 1:
int main()
{
int i; // the compiler will only warn about i being uninitialized
int j= i;
int k= k; // the compiler has no problem with this
return i+j+k; // no warning about k being possibly uninitialized
}
Example 2:
class A {
int x;
};
int main() {
A* aptr= (A*)aptr; // why is this line valid?
return (aptr==0); // aptr isn't _really_ initialized, but no warning...
}
--
Summary: g++ allows variable to be initialized by value of
variable being initialized
Product: gcc
Version: 3.4.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gahs at phys dot ksu dot edu
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24157
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-10-01 15:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-01 6:58 [Bug c++/24157] New: g++ allows variable to be initialized by value of variable being initialized gahs at phys dot ksu dot edu
2005-10-01 15:40 ` [Bug c++/24157] " pinskia at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).