Opened 3 years ago

Last modified 3 years ago

#227 new defect

Interpretation of assertions with struct declaration

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

Description (last modified by mlbrooks)

Currently, assertion parameters placed on a struct declaration is interpreted as assertion on special operators (ctor/dtor/assign), which means they might be elided or forcefully bypassed.

Some test results:

forall (otype T | {void foo(T);})
struct S {
  T t;

S(int) s1; // error: cannot satisfy assertion for ?{}
S(int) s2 = {0}; // error: cannot satisfy assertion for ?{}
S(int) s3 @= {0}; // ok ...?

forall (otype T | {void foo(T);})
struct U {
  T * t;

U(int) u1; // ok ...?

A problem comes up, under the "business as usual" interpretation, that the assertions apply to the autogen functions. The problem is that it is possible to declare custom constructors or destructors with fewer assertions than the autogen ones; by the specialization cost element, the custom ones are less specialized than the autogen ones, so the autogen ones are still preferred.

trait is_happy( otype T ) {
    void sayHi(T);

forall( otype T           | is_happy(T) )
struct thing { T item; };

forall( otype T
                          | is_happy(T)
void ^?{}( thing(T) & ) {
    printf("custom dtor called\n");

void sayHi(float) {}

int main() {
    thing(float) x;

Actual, plain compile: Compile succeeds; run produces no output, showing the custom destructor was not called.

Expected, plain compile: Error, you are obviously trying to declare a destructor, but because your declaration is missing an assertion, it will never be chosen.

Actual and expected -DREMEMBER_ASSN: Compile succeeds, custom destructor is called. This is the state that the expected error will help the programmer reach.

Change History (1)

comment:1 Changed 3 years ago by mlbrooks

Description: modified (diff)
Note: See TracTickets for help on using tickets.