Opened 4 years ago

Closed 4 years ago

#230 closed defect (fixed)

Deleted declaration (=void) is available via assertion

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

Description

// Our Rule:  Anything except float can say hi

forall( dtype T )
void sayHi( T & o ) {
    printf("Object at %p is saying hi\n", & o);
}

void sayHi( float & ) = void;

// Test 1 (correct today): A direct call to sayHi respects the rule stated above

void test1() {
    int i;
    printf("Object at %p is an int\n", & i);
    sayHi(i);

    float f;
    printf("Object at %p is a float\n", & f);
  #ifdef TRY_FORBIDDEN
    sayHi(f);
  #endif
}

// Test2 (incorrect today): An assertion-mediated call to sayHi disregards the rule stated above

trait can_speak( dtype T ) {
    void sayHi( T & );
};

forall( dtype T | can_speak(T) )
void forceSpeak( T & o ) {
    sayHi( o );
}

void test2() {
    int i;
    printf("Object at %p is an int\n", & i);
    forceSpeak(i);

    float f;
    printf("Object at %p is a float\n", & f);
    forceSpeak(f);
}

// Top-level driver

int main() {
    test1();
    printf("-----\n");
    test2();
}

-DTRY_FORBIDDEN actual and expected: compiler error, Unique best alternative includes deleted identifier at sayHi(f) call in test1

plain Actual: compiles successfully and runs with output

Object at 0x7fffffffe2f0 is an int
Object at 0x7fffffffe2f0 is saying hi
Object at 0x7fffffffe2f4 is a float
-----
Object at 0x7fffffffe2b8 is an int
Object at 0x7fffffffe2b8 is saying hi
Object at 0x7fffffffe2bc is a float
Object at 0x7fffffffe2bc is saying hi

plain Expected: compiler error, Unique best alternative includes deleted identifier at forceSpeak(f) call in test2

Change History (1)

comment:1 Changed 4 years ago by f37yu

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