Opened 2 years ago

#257 new defect

Pointer arithmetic silently adds narrowing conversions

Reported by: mlbrooks Owned by:
Priority: minor Component: cfa-cc
Version: 1.0 Keywords:
Cc:

Description

int main() {
    int *a, *b, x;
    b = a + 3.5;
    x = a[3.5];
    x = (3.5)[a];
}

All three seem to be asking for pointer + double, which is nonsense.

CFA, actual: Compiles successfully. The 3.5 is rounded down to the integral 3. The generated code includes the lines:

((void)(_X1bPi_2=(_X1aPi_2+((signed long int )3.5))));
((void)(_X1xi_2=_X1aPi_2[((signed long int )3.5)]));
((void)(_X1xi_2=((signed long int )3.5)[_X1aPi_2]));

GCC, actual: Compilation errors on all three: "invalid operands to binary + (have ‘int *’ and ‘double’)" or "array subscript is not an integer"

Change History (0)

Note: See TracTickets for help on using tickets.