https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67386
Bug ID: 67386
Summary: missing diagnostic on a use of an undeclared function
Product: gcc
Version: 5.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
GCC isn't completely consistent in diagnosing references to undeclared
functions. In the test case below, it issues an error for only the last three
out of the four definitions of foo. It issues a warning for the first one,
even though it too references an undeclared identifier.
Versions prior to 5.1 diagnosed only the second and fourth forms.
$ (set -x && cat t.c && for i in 1 2 3 4; do ~/bin/gcc-5.1.0/bin/gcc -DFOO=$i
-c t.c; done)
+ cat t.c
#if FOO == 1
void* foo (int i) {
return i ? foobar (i) : foobar;
}
#elif FOO == 2
void* foo (int i) {
return i ? 0 : foobar;
}
#elif FOO == 3
void* foo (int i) {
if (i)
return foobar (i);
else
return foobar;
}
#else
void* foo (int i) {
if (i)
return 0;
else
return foobar;
}
#endif
+ for i in 1 2 3 4
+ /home/msebor/bin/gcc-5.1.0/bin/gcc -DFOO=1 -c t.c
t.c: In function ‘foo’:
t.c:3:16: warning: implicit declaration of function ‘foobar’
[-Wimplicit-function-declaration]
return i ? foobar (i) : foobar;
^
t.c:3:27: warning: pointer/integer type mismatch in conditional expression
return i ? foobar (i) : foobar;
^
+ for i in 1 2 3 4
+ /home/msebor/bin/gcc-5.1.0/bin/gcc -DFOO=2 -c t.c
t.c: In function ‘foo’:
t.c:7:20: error: ‘foobar’ undeclared (first use in this function)
return i ? 0 : foobar;
^
t.c:7:20: note: each undeclared identifier is reported only once for each
function it appears in
+ for i in 1 2 3 4
+ /home/msebor/bin/gcc-5.1.0/bin/gcc -DFOO=3 -c t.c
t.c: In function ‘foo’:
t.c:12:16: warning: implicit declaration of function ‘foobar’
[-Wimplicit-function-declaration]
return foobar (i);
^
t.c:12:16: warning: return makes pointer from integer without a cast
[-Wint-conversion]
t.c:14:16: error: ‘foobar’ undeclared (first use in this function)
return foobar;
^
t.c:14:16: note: each undeclared identifier is reported only once for each
function it appears in
+ for i in 1 2 3 4
+ /home/msebor/bin/gcc-5.1.0/bin/gcc -DFOO=4 -c t.c
t.c: In function ‘foo’:
t.c:21:16: error: ‘foobar’ undeclared (first use in this function)
return foobar;
^
t.c:21:16: note: each undeclared identifier is reported only once for each
function it appears in