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 ();
      |       ^~~~~~

Reply via email to