Opened 2 years ago

#258 new defect

Unclear intended type for char literal

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

Description

Bug or feature? Here is a case of C disagreeing with CFA. Are we okay with it? If so, we need to fix CFA's behaviour to be self-consistent. If not, we need to reconcile this point of C compatibility with our rules for overload selection.

C's preferred type for 'x' is int. Today's CFA mostly prefers type char.

This disagreement is a point of backward incompatibility. Yet, CFA's overloading provides precedent for "CFA is right."

The incompatibility:

#include <stdio.h>

int main( int argc, char ** argv ) {
    printf("sizeof('x') is %ld\n", sizeof('x'));

    typeof('x') var = 'x';
    printf("sizeof(var) is %ld\n", sizeof(var));

    printf("sizeof(typeof('x')) is %ld\n", sizeof(typeof('x')));
}

CFA, actual:

sizeof('x') is 4
sizeof(var) is 1
sizeof(typeof('x')) is 1

GCC, actual:

sizeof('x') is 4
sizeof(var) is 4
sizeof(typeof('x')) is 4

Proposed self-consistent, for CFA:

sizeof('x') is 1
sizeof(var) is 1
sizeof(typeof('x')) is 1

Precedent for, "'x' should be a char." (Code is CFA only)

void f( int ) {
    printf("int overload called\n");
}

void f( char ) {
    printf("char overload called\n");
}

int main( int argc, char ** argv ) {
    typeof('q') var;
    printf("%ld\n", sizeof(var));
    f( 'q' );
    f( var );
}

CFA, actual and expected:

1
char overload called
char overload called

Change History (0)

Note: See TracTickets for help on using tickets.