Opened 6 months ago

Closed 5 months ago

#304 closed defect (fixed)

Polymorphic self reference does not work

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

Description (last modified by mlbrooks)

    forall( tE & )
    struct thing {
        thing(tE) *a;
        thing(tE) *b;
    };

Actual: cfa emits bad code: gcc reports parse errors

Expected: compiles (-c) successfully

Observation: cfa -CFA -XCFA,-p gives the fragment:

    struct thing {
        struct thing()  *_X1aPS5thing_Y13__tE_generic___1;
        struct thing *_X1bPS5thing_Y13__tE_generic___1;
    };

Note the field a has extra parentheses (bad C syntax)
Note the field b is being emitted correctly

Either of the following "workaround" declarations (struct or function parameter) is enough, on its own, to make thing's self-reference work. The fact that a thing(tE) * field is valid in the workaround position suggests that self-reference is an essential part of the problem.

Working theory: the compile unit's first reference to a type cannot be a self reference.

    forall( tE & ) {
        struct thing;
        struct workaround_t {
            thing(tE) * x;
        };
        void * workaround( thing(tE) * );  // never defined
        struct thing{
            thing(tE) *a;
            thing(tE) *b;
        };
    }

Change History (2)

comment:1 by mlbrooks, 6 months ago

Description: modified (diff)
Priority: majorminor

Simplified the workaround considerably and added cause-effect discussion.

Reduced priority, given ease to work around.

comment:2 by ajbeach, 5 months ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.