cc65: Missing diagnostics: "invalid constant"

Consider this code:

int x = 0xe+1;

Expected diagnostics:

invalid constant

Actual diagnostics:

<nothing>

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 18 (11 by maintainers)

Most upvoted comments

Well, I just fixed this by the way when I was working on a preprocessor fix. Before fix:

int a1 = 0xE+1;     /* WRONG: no error? */
int a2 = 0xP-1;     /* BAD: endless errors */
int a3 = 0xP1;      /* Error: ';' expected */
int b1 = 0x;        /* WRONG: no error? */
int b2 = 0b;        /* WRONG: no error? */
int c1 = 08;        /* Error: Numeric constant contains digits beyond the radix */
int c2 = 0b12;      /* BAD: endless errors */
int d1 = 0xEP-1.1;  /* BAD: endless errors */
int d2 = 0xEP;      /* Error: ';' expected */
int d3 = 0007f;     /* Error: ';' expected */
int d4 = 7f.;       /* Error: Invalid suffix "f." on integer constant */
int d5 = 0008.;     /* OK */

After fix:

int a1 = 0xE+1;     /* Error: Invalid suffix "+1" on integer constant */
int a2 = 0xP-1;     /* Error: Invalid suffix "xP-1" on integer constant */
int a3 = 0xP1;      /* Error: Invalid suffix "xP1" on integer constant */
int b1 = 0x;        /* Error: Invalid suffix "x" on integer constant */
int b2 = 0b;        /* Error: Invalid suffix "b" on integer constant */
int c1 = 08;        /* Error: Invalid digit "8" beyond radix 8 constant */
int c2 = 0b12;      /* Error: Invalid digit "2" beyond radix 2 constant */
int d1 = 0xEP-1.1;  /* Error: Invalid suffix ".1" on floating constant */
int d2 = 0xEP;      /* Error: Floating constant exponent has no digits */
int d3 = 0007f;     /* Error: Invalid suffix "f" on integer constant */
int d4 = 7f.;       /* Error: Invalid suffix "f." on integer constant */
int d5 = 0008.;     /* OK */

C11, 5.1.1.2 Translation phases, 7:

Each preprocessing token is converted into a token.

C11, 6.4 Lexical elements, Syntax, 1:

preprocessing-token:
    header-name
    identifier
    pp-number
    character-constant
    string-literal
    punctuator
    each non-white-space character that cannot be one of the above

C11, 6.4.8 Preprocessing numbers, Syntax, 1:

pp-number:
    digit
    . digit
    pp-number digit
    pp-number identifier-nondigit
    pp-number e sign
    pp-number E sign
    pp-number p sign
    pp-number P sign
    pp-number .

The 0xe+1 is a pp-number, which is an instance of preprocessing-token. Hence, the preprocessing token 0xe+1 is required to be converted into a token 0xe+1, which is an invalid token (invalid constant). A conforming implementation shall produce at least one diagnostic message.