c++/2178: ignoring of an unitialized reference error

mik@usc.edu mik@usc.edu
Mon Mar 5 02:26:00 GMT 2001


>Number:         2178
>Category:       c++
>Synopsis:       ignoring of an unitialized reference error
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Mon Mar 05 02:26:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Mikhail Dikovsky
>Release:        gcc version 2.95.2 20000220 (Debian GNU/Linux)
>Organization:
>Environment:
MACHTYPE=i386
HOSTTYPE=i386-linux
OSTYPE=linux
>Description:
The compiler does not complain about an erroneous code that
results in a reference being uninitialized. The file "a.cc"
compiles with no errors, although it should produce an error
message or a warning at least.
The problem occurs in the constuctor A(int&):
struct A
{
	int& num;
	A(int &Num) : num(num) {} 
	// Here we mistakenly initialize num with *itself* instead of Num.
};
>How-To-Repeat:
g++ -Wall a.cc
>Fix:
Add an error message or a warning.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/x-c++src; name="a.cc"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="a.cc"

c3RydWN0IEEKewoJaW50JiBudW07CglBKGludCAmTnVtKSA6IG51bShudW0pIHt9IAoJLy8gSGVy
ZSB3ZSBtaXN0YWtlbmx5IGluaXRpYWxpemUgbnVtIHdpdGggKml0c2VsZiogaW5zdGVhZCBvZiBO
dW0uCgkvLyBUaGUgcmVmZXJlbmNlIG51bSBiZWNvbWVzIHVuaW5pdGlhbGl6ZWQsIHBvaW50aW5n
IHRvIGFuIGFyYml0cmFyeQoJLy8gbWVtb3J5IGxvY2F0aW9uLiBUaGUgY29tcGlsYXRpb24gb2Yg
dGhpcyBjb2RlIHNob3VsZCBnZW5lcmF0ZSBhbiAKCS8vIGVycm9yIChvciBhIHdhcm5pbmcgYXQg
bGVhc3QpLCBhbHRob3VnaCBpdCBjb21waWxlcyBjbGVhbmx5Lgp9OwoKaW50IG1haW4oKQp7Cglp
bnQgTnVtOwoJQSBhKE51bSk7CglhLm51bSA9IDM7ICAvLyB0aGlzIHN0YXRlbWVudCB1c3VhbGx5
IGNhdXNlcyBhIHNlZ21lbnRhdGlvbiBmYXVsdAoJcmV0dXJuIDA7Cn0K



More information about the Gcc-bugs mailing list