From mboxrd@z Thu Jan 1 00:00:00 1970 From: mtodorov@alu.hr To: gcc-gnats@gcc.gnu.org Subject: c/2776: Wrong (misleading) error message in gcc 2.95.3 Date: Tue, 08 May 2001 10:56:00 -0000 Message-id: <20010508174624.17779.qmail@sourceware.cygnus.com> X-SW-Source: 2001-05/msg00230.html List-Id: >Number: 2776 >Category: c >Synopsis: Wrong (misleading) error message in gcc 2.95.3 >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: change-request >Submitter-Id: net >Arrival-Date: Tue May 08 10:56:01 PDT 2001 >Closed-Date: >Last-Modified: >Originator: Mirsad Todorovac >Release: gcc 2.95.3 >Organization: >Environment: alpha-dec-osf4.0b gcc-2.95.3 gmake 3.79 tcsh 6.10.00 >Description: When the following code was compiled: 99 if(_GrFontFileInfo.npath < 0) { 100 char *fPath = getenv("GRXFONT"); 101 #ifdef GRX_DEFAULT_FONT_PATH 102 if (!fPath) fPath = GRX_DEFAULT_FONT_PATH; 103 #endif 104 GrSetFontPath(fPath); 105 } gcc 2.95.3 returned following error message: text/loadfont.c:102: parse error before `/' text/loadfont.c:102: warning: empty body in an if-statement Gcc was invoked by gmake with following options: gcc -c -O6 -Wall -W -Wshadow -Wpointer-arith \ -Wbad-function-cast -Wcast-align -Wconversion \ -Wmissing-prototypes -Wnested-externs -Wstrict-prototypes \ -DGRX_DEFAULT_FONT_PATH="/usr/local/lib/grx/fonts" \ -DSMALL_STACK -fomit-frame-pointer -D__XWIN__ -I. \ -I./include -I../include -I/usr/X11R6/include \ -I../addons/print -I../addons/bmp text/loadfont.c \ -o text/loadfont.o I couldn't decrypt what it meant until I tried gcc -E (running preprocessor to see what the compiler is really looking at) and I carefully found the line 102 of loadfont.c after header inclusion. I've found this: 99 if(_GrFontFileInfo.npath < 0) { 100 char *fPath = getenv("GRXFONT"); 101 102 if (!fPath) fPath = /usr/local/lib/grx/fonts ; 103 104 GrSetFontPath(fPath); 105 } Now it's obvious what the error is: the path was left without quotes, although in Makefile it has quotes (the shell probably stripped them). But from error message "empty body in an if-statement" it cannot be seen. The right error message should be "invalid expression" or something like that. I understand that gcc can't "see" that this is actually an error in macro definition of GRX_DEFAULT_FONT_PATH. Changing definition of GRX_DEFAULT_FONT_PATH to \"/usr/local/lib/grx/fonts\" resolved the problem with GRX build (as for now), but misleading error message in gcc remains ... Mirsad Todorovac >How-To-Repeat: cat > repeat.c int main(int argc, char* argv[]) { char *fPath = 0; if (!fPath) fPath = /usr/local/share/grx/fonts ; } ^D gcc -c -O6 -Wall -W -Wshadow -Wpointer-arith \ -Wbad-function-cast -Wcast-align -Wconversion \ -Wmissing-prototypes -Wnested-externs -Wstrict-prototypes \ -DGRX_DEFAULT_FONT_PATH=\"/usr/local/lib/grx/fonts\" \ -DSMALL_STACK -fomit-frame-pointer repeat.c >Fix: Try to give a correct error message, like "bad expression: have you forgot quotes on '/usr/local/lib/grx/fonts'?" >Release-Note: >Audit-Trail: >Unformatted: