Opened 5 years ago

Closed 20 months ago

#122 closed defect (fixed)

Reference assignment

Reported by: pabuhr Owned by:
Priority: major Component: cfa-cc
Version: 1.0 Keywords:


The last line compiles when the RHS type is wrong.

int i = 7;
int & r = i;
int * pi = &r;
int & r3 = &r;

The type of &r is int * allowing the assignment to pi.

In the last line, the initialization puts an implicit & before &r, so the result is address of r, which has type int &, and the assignment is allowed because the types match. But r3 must point to an int, not an int &. I have verified that r3 is pointing at r not i;

Change History (1)

comment:1 Changed 20 months ago by Thierry Delisle

Resolution: fixed
Status: newclosed

Last line no longer compiles.

Note: See TracTickets for help on using tickets.