Opened 4 months ago

Last modified 4 months ago

#299 new defect

Unusable overload allowed, between array and pointer

Reported by: mlbrooks Owned by:
Priority: major Component: cfa-cc
Version: 1.0 Keywords: overload shadow scope array decay
Cc:

Description ΒΆ

    #ifndef SUPPRESS_COMP_ERR
    void f1() {
        int a[100];
        int *a;                     // dup
        a[0];                       // ambiguous
    }

    void f2() {
        int *a;
        int a[100];                 // dup
        a[0];                       // ambiguous
    }
    #endif

    int a[100];

    void f3() {
        int x = 42;
        int *a = & x;
        printf("%d\n", a[0]);       // ambiguous
    }

    void f4( int *a ) {
        printf("%d\n", a[0]);       // ambiguous
    }

    void f5( int a[100] ) {
        printf("%d\n", a[0]);       // ambiguous
    }

    int main() {
        int x = 42;
        f3();
        f4( & x );
        f5( & x );
        return 0;
    }

CFA actual (with and without -DSUPPRESS_COMP_ERR): compiler rejection "Cannot choose between 2 alternatives for a" at all five lines commented "ambiguous"

GCC actual, CFA exptected (without -DSUPPRESS_COMP_ERR): compiler rejection "conflicting types" or "duplicate definition" at two lines commented "dup"

GCC actual, CFA exptected (with -DSUPPRESS_COMP_ERR): runs and prints "42" three times

Change History (2)

comment:1 Changed 4 months ago by f37yu

CFA variable overloading currently takes over C variable shadowing (when the variable defined in the inner scope has a different type than the one in the outer scope). Are you suggesting that array type and its decayed pointer type should be considered conflicting types and apply the shadowing rules?

comment:2 Changed 4 months ago by mlbrooks

Yes, an array type and its decayed pointer type should be considered conflicting types.

Note: See TracTickets for help on using tickets.