[cfe-dev] "expected function body" diagnostic rewording

Carl-Daniel Hailfinger c-d.hailfinger.devel.2006 at gmx.net
Sat Jul 10 16:45:26 PDT 2010


Hi,

I just stumbled across a typo in a header file of a heavily modified
flashrom codebase which looked like this:

int write_sector_jedec_common(struct flashchip *flash, uint8_t *src, int start, int len, unsigned int mask)
/* m29f400bt.c */
int probe_m29f400bt(struct flashchip *flash);


Note the missing semicolon for the write_sector_jedec_common prototype.

gcc (4.2.1) has this diagnostic:
jedec.c: In function ‘write_sector_jedec_common’:
jedec.c:35: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
jedec.c:42: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
jedec.c:62: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
jedec.c:74: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
jedec.c:79: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
jedec.c:96: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
jedec.c:104: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
jedec.c:204: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
jedec.c:234: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
jedec.c:263: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
jedec.c:293: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
jedec.c:322: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
jedec.c:341: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
jedec.c:379: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
jedec.c:399: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
jedec.c:417: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
jedec.c:428: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
jedec.c:441: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
jedec.c:449: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
jedec.c:457: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
jedec.c:465: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
jedec.c:470: error: old-style parameter declarations in prototyped function definition
jedec.c:470: error: expected ‘{’ at end of input
cc1: warnings being treated as errors
jedec.c:470: warning: no return statement in function returning non-void


clang (llvm-clang-2.6.99svn97231) has this diagnostic:
In file included from jedec.c:26:
./chipdrivers.h:83:1: error: expected function body after function declarator
int probe_m29f400bt(struct flashchip *flash);
^
1 diagnostic generated.


While the clang diagnostic was a lot more helpful in pinpointing the
actual error because it complained about the header instead of the
source file including it, the diagnostic could be improved a bit by the
following:
- Change the wording from "error: expected function body after function
declarator" to "error: expected function body or semicolon after
function declarator/prototype".
- Print the preceding code line as well because that's where the
semicolon is missing.

Regards,
Carl-Daniel

-- 
http://www.hailfinger.org/




More information about the cfe-dev mailing list