[Bug preprocessor/81419] New: GCC wrongly suggests function-like macro as fixit hint for undefined object-like macro
egall at gwmail dot gwu.edu
gcc-bugzilla@gcc.gnu.org
Wed Jul 12 17:24:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81419
Bug ID: 81419
Summary: GCC wrongly suggests function-like macro as fixit hint
for undefined object-like macro
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: preprocessor
Assignee: unassigned at gcc dot gnu.org
Reporter: egall at gwmail dot gwu.edu
CC: dmalcolm at redhat dot com
Target Milestone: ---
Host: i386-apple-darwin9.8.0
Target: i386-apple-darwin9.8.0
Build: i386-apple-darwin9.8.0
Testcase:
$ cat macro_fixit.c
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
int foo(unsigned int argument);
int bar(void)
{
return foo(PTR_SIZE);
}
Compiling gives:
$ /usr/local/bin/gcc -c macro_fixit.c
macro_fixit.c: In function ‘bar’:
macro_fixit.c:7:13: error: ‘PTR_SIZE’ undeclared (first use in this function);
did you mean ‘ARRAY_SIZE’?
return foo(PTR_SIZE);
^~~~~~~~
ARRAY_SIZE
macro_fixit.c:7:13: note: each undeclared identifier is reported only once for
each function it appears in
However, making the replacement that the fixit hint suggests is invalid, and
still leads to another error:
$ /usr/local/bin/gcc -c macro_fixit.c
macro_fixit.c: In function ‘bar’:
macro_fixit.c:7:13: error: ‘ARRAY_SIZE’ undeclared (first use in this function)
return foo(ARRAY_SIZE);
^~~~~~~~~~
macro_fixit.c:7:13: note: each undeclared identifier is reported only once for
each function it appears in
IMO gcc should only suggest replacements as fixit hints when they actually fix
the problem being pointed out.
Version info:
$ /usr/local/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/usr/local/bin/gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/i386-apple-darwin9.8.0/8.0.0/lto-wrapper
Target: i386-apple-darwin9.8.0
Configured with: ../configure --disable-werror --disable-werror-always
--enable-languages=c,c++,lto,objc,obj-c++ --enable-stage1-checking=release,rtl
-C --with-system-libunwind --enable-secureplt --enable-frame-pointer
--enable-debug --with-isl --disable-host-shared --enable-maintainer-mode
--disable-default-pie --with-ld64 --without-pic --enable-target-optspace
CC=/usr/local/bin/gcc CXX=/usr/local/bin/g++ AUTOCONF=/usr/local/bin/autoconf
AUTOHEADER=/usr/local/bin/autoheader AUTORECONF=/usr/local/bin/autoreconf
AUTOM4TE=/usr/local/bin/autom4te AUTOSCAN=/usr/local/bin/autoscan
AUTOUPDATE=/usr/local/bin/autoupdate IFNAMES=/usr/local/bin/ifnames
Thread model: posix
gcc version 8.0.0 20170702 (experimental) (GCC)
More information about the Gcc-bugs
mailing list