Opened 6 years ago

Closed 2 years ago

#122 closed defect (fixed)

Reference assignment

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

Description

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 2 years ago by Thierry Delisle

Resolution: fixed
Status: newclosed

Last line no longer compiles.

Note: See TracTickets for help on using tickets.