public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/95445] New: diagnose incompatible calls to functions declared without prototype
@ 2020-05-30 22:32 msebor at gcc dot gnu.org
  2020-05-30 22:32 ` [Bug c/95445] " msebor at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-05-30 22:32 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95445
           Summary: diagnose incompatible calls to functions declared
                    without prototype
           Product: gcc
           Version: 10.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 silently accepts calls to built-in functions declared without a prototype
as long as the arguments match the expected types (based on the prototype
hardcoded into GCC), but issues warnings for calls where the arguments don't
match.

But GCC makes no attempt to make sure that in calls to other (i.e.,
non-built-in) functions declared without prototype provided arguments have the
same type across all the calls.  Diagnosing mismatches as suggested in the
comments below would help detect bugs caused by their incompatibily.

This enhancement is different from pr92212 which is about calls to K&R
functions defined in the same translation unit.

$ cat x.c && gcc -O2 -S -Wall x.c
char* strchr ();

char* f0 (const char *s)
{
  return strchr (s, 'x');    // no warning (okay)
}

char* f1 (const char *s)
{
  return strchr (s, "y");    // warning (good)
}

void g ();

void h (void)
{
  g (1);                     // (presumably) okay, f's type is 'void (int)'
  g ("foo");                 // should be diagnosed
  g (1, "bar");              // ditto
}
x.c: In function ‘f1’:
x.c:10:21: warning: passing argument 2 of ‘strchr’ makes integer from pointer
without a cast [-Wint-conversion]
   10 |   return strchr (s, "y");    // warning (good)
      |                     ^~~
      |                     |
      |                     char *
x.c:1:7: note: expected ‘int’ but argument is of type ‘char *’
    1 | char* strchr ();
      |       ^~~~~~

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-05-12 16:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-30 22:32 [Bug c/95445] New: diagnose incompatible calls to functions declared without prototype msebor at gcc dot gnu.org
2020-05-30 22:32 ` [Bug c/95445] " msebor at gcc dot gnu.org
2021-10-27  5:21 ` egallager at gcc dot gnu.org
2023-05-12 15:54 ` fw at gcc dot gnu.org
2023-05-12 16:29 ` sjames at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).