drh / lcc

The lcc retargetable ANSI C compiler
https://drh.github.io/lcc/
2.03k stars 441 forks source link

Fixed to correctly diagnose expressions with NPC #13

Open mycoboco opened 9 years ago

mycoboco commented 9 years ago

This commit lets lcc correctly diagnose the following code:

typedef void (*fp_t)(void);

fp_t func(fp_t param)
{
    return (void *)0;          /* line A */
}

int main(void)
{
    fp_t t = (void *)0;       /* line B */
    t = (void *)0;            /* line C */
    return func((void *)0)    /* line D */
               == (void *)0;
}

According to the Standard, the commented lines above should not be considered non-portable while lcc says:

5: warning: conversion from `pointer to void' to `pointer to void function(void)' is compiler dependent
10: warning: conversion from `pointer to void' to `pointer to void function(void)' is compiler dependent
11: warning: conversion from `pointer to void' to `pointer to void function(void)' is compiler dependent
12: warning: conversion from `pointer to void' to `pointer to void function(void)' is compiler dependent

EDIT: an example regarding a conditional expression and NPC has been removed because it was wrong; constant expressions can be or have conditional expressions. No problem with them in lcc.