Opened 4 years ago

#208 new defect

Zero-pointer literal does not work as an argument for a const parameter

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

Description

This issue seems to be a case of the #189 fix going too far: a typed pointer use that was working, and that should be allowed, is now failing.

void f( const float * ) {}

int main() {
    f( 0p );
}

Actual: No reasonable alternatives for expression ... Application of ... intptr

Expected: compiles successfully

An explicit cast is a workaround:

void f( const float * ) {}

int main() {
    f( (const float *) 0p );
}

Actual and Expected: compiles successfully

Indirection through a named constant is a workaround:

void f( const float * ) {}

int main() {
    const float * arg = 0p;
    f( arg );
}

Actual and Expected: compiles successfully

Further notes summarize investigation already done.

When the declaration of the intptr function is moved from the builtins to the current file, it starts working.

The 0p literal desugars as:

void f( const float * ) {}

int main() {
    f( intptr(0) );
}

Actual: No reasonable alternatives for expression ... Application of ... intptr

Expected: compiles successfully

With the equivalent declaration inline:

// up to name change, copied from builtins.c
static inline forall( dtype DT )
DT * intptr2( uintptr_t addr ) { return (DT *)addr; }

void f( const float * ) {}

int main() {
    f( intptr2(0) );
}

Actual and Expected: compiles successfully

When the error happens, the resolver pass is completing successfully, and the No Reasonable Alternatives finding is coming from the FixInit? pass

cfa-cpp -p -P astexpr ... of any failing case still prints an AST.

Change History (0)

Note: See TracTickets for help on using tickets.