Opened 4 years ago

Last modified 4 years ago

#203 new defect

Polymorphic Structure Initalization Errors — at Version 3

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

Description (last modified by ajbeach)

So I am pretty sure there is more than one bug here, but I'm not entirely sure where the lines are. There are a few places nothing is found, a few times extra options are found. There are times initialization style matters and there are times it doesn't.

Just because it might be a problem I made it a bit easier to pick out each one.

// Can be changed here or on the command line.
#ifndef SHOW_ERROR
#define SHOW_ERROR 0
#endif

forall(dtype A)
struct empty {
    // Nothing.
};

forall(dtype B)
struct counter {
    int count;
};

forall(dtype C)
struct wrap_e {
    empty(C) field;
};

forall(dtype D)
struct wrap_c {
    counter(D) field;
};

forall(dtype E)
struct wrap_d {
    E * field;
};

forall(otype F)
struct wrap_o {
    F field;
};

forall(dtype G)
struct base_vtable {
    base_vtable(G) const * const parent;
};

forall(dtype H)
struct child_vtable {
    base_vtable(H) const * const parent;
};

empty(int) empty_obj = {};
empty(char) empty_obj = {};
counter(int) count_obj = {5};
counter(char) count_obj = {5};

base_vtable(int) base_vtable_instance @= { 0 };
base_vtable(char) base_vtable_instance @= { 0 };

#if SHOW_ERROR == 2
// No alternatives:
wrap_e(char) error_obj @= { empty_obj };

#elif SHOW_ERROR == 3
// 2 alternatives:
wrap_c(int) error_obj @= { count_obj };

#elif SHOW_ERROR == 4
void local(void) {
    // 2 alternatives:
    wrap_c(char) error_obj @= { inner_obj };
}

#elif SHOW_ERROR == 5
// 2 alternatives:
child_vtable(int) child_vtable_instance = {
    &base_vtable_instance
};

#elif SHOW_ERROR == 6
// 2 alternatives:
child_vtable(char) child_vtable_instance @= {
    &base_vtable_instance
};

#elif SHOW_ERROR == 7
// Initalizer too deep:
wrap_e(bool) error_obj = { {} };

#elif SHOW_ERROR == 8
// Initalizer too deep:
wrap_c(bool) error_obj = { { 0 } };

#elif SHOW_ERROR == 9
// Assertion failure:
wrap_e(bool) error_obj @= { {} };

#endif

// Related things that do not produce errors.

int some_int = -7;
char some_char = 'c';

wrap_e(int) wrap_obj = { empty_obj };
wrap_c(int) wrap_obj = { count_obj };
wrap_d(int) wrap_obj = { &some_int };
wrap_d(char) wrap_obj @= { &some_char };
wrap_o(int) wrap_obj = { 13 };
wrap_o(char) wrap_obj @= { 'c' };

int main(void) {
    wrap_e(int) wrap_obj = { empty_obj };
    wrap_c(int) wrap_obj = { count_obj };
    wrap_d(int) wrap_obj = { &some_int };
    wrap_d(char) wrap_obj @= { &some_char };
    wrap_o(int) wrap_obj = { 13 };
    wrap_o(char) wrap_obj @= { 'c' };

    {
        wrap_e(bool) alpha;
        wrap_e(bool) beta;
        beta = alpha;
        // alpha.field = beta.field; (See #166.)
        wrap_e(bool) delta = { beta };
    }
    {
        wrap_c(bool) alpha;
        wrap_c(bool) beta;
        beta = alpha;
        // alpha.field = beta.field; (See #166.)
        wrap_c(bool) delta = { beta };
    }

    return 0;
}

Change History (3)

comment:1 Changed 4 years ago by ajbeach

Description: modified (diff)

comment:2 Changed 4 years ago by ajbeach

Description: modified (diff)
Summary: Polymorphic Structure and Polymorphic Structure ErrorsPolymorphic Structure Initalization Errors

Some of the error cases may have actually been bad code. I removed them and renamed the ticket to hopefully describe the remaining cases better. I also included some more examples of code that do work because I dug up a few cases (copy constructor) that does work. Also I dug up a few more cases that are errors but are almost certainly other errors, maybe this ticket should be split up.

comment:3 Changed 4 years ago by ajbeach

Description: modified (diff)

One of the cases actually did work, removed the old first case.

Note: See TracTickets for help on using tickets.