[Bug c/67386] missing diagnostic on a use of an undeclared function

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sun Aug 30 16:50:00 GMT 2015


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67386

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
>From Doug Gwyn's response on the WG14 list about the C90 wording with respect
to the placement of the implicit declaration (quoted below) it seems that even
though diagnosing line 11 in f2() in comment #2 goes against a strict
interpretation of the C90 rule, it is in the spirit of the original K&R C and
the consequences of the strict interpretation may not have been intended.

After thinking about it some more, it doesn't seem worthwhile to open a new bug
for this.  It would likely and up getting closed as WONTFIX anyway since
changing the behavior would only serve to break legacy code.

>> ... But again, I'm  surprised to find that some compilers inject it just
> before the call
>> to the function, while others inject it "at the top of the  block."
>> The former compilers then issue an error for the first reference to  foo
> below:
>>       void bar (int i, int (*p)(int))  {
>>           p =  foo;        /* valid? */
>>   i = foo (i);
>>   }
> 
> One could reasonably argue that the "top of the block" compilers more
> accurately
> implement the C90 wording; however, Ritchie's PDP-11 C compiler (which I
> continue to
> enhance and maintain) enacts an implicit declaration of "foo" (as an extern
>   int in this
> example) at the first place it is seen, and therefore issues an error for
> the second,
> incompatible occurrence.  This compiler was designed to be pretty much
> "one pass".



More information about the Gcc-bugs mailing list