This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/70114] New: Incompatible implicit function prototype when parameters match


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

            Bug ID: 70114
           Summary: Incompatible implicit function prototype when
                    parameters match
           Product: gcc
           Version: 5.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tanzx940228 at hotmail dot com
  Target Milestone: ---

Created attachment 37883
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=37883&action=edit
All the 3 examples shown in the comment.

Brief:
A function call in a scope where no prototype is given triggers an error, when
the parameters match a prototype given in a different scope.

Detail: I'm going to show 3 examples. The bug is shown in the 3rd example. All
3 examples are standalone .c files.

1.correct.c
-----------

int main() {
    {
        int foo(int arg);
        foo(3);
    }
    {
        int foo(float arg0, float arg1); // both gcc and clang get errors
        return foo(3.0f, 4.0f);
    }
}

Note that different prototypes are given in different scopes. Both gcc and
clang treat this as an error. This means they both think that a function can
only have one prototype throughout the translation unit - totally reasonable.


2.gcc.okay.c
------------

int main() {
    {
        int foo(int arg);
        foo(3);
    }
    {
        foo(3.0f, 4.0f); // gcc passes, clang gets an error
    }
}

In this example, the second usage of 'foo' is in a scope with no prototype
given. Clang is smart enough to tell you that there is a prototype in another
scope, and the parameters in the call don't match that prototype. gcc compiles
this program (with a warning) - which is acceptable. Maybe gcc thinks that it's
the user's responsibility to check the parameters if he doesn't give a
prototype in the scope.


3.gcc.error.c
-------------
int main() {
    {
        int foo(float arg0, float arg1);
        foo(3.0f, 4.0f);
    }
    {
        foo(3.0f, 4.0f); // clang passes, gcc gets an error???
    }
}

This is really weird! Clang gives me a warning saying that I'm using an
out-of-scope prototype. BUT gcc gives me an error, saying "incompatible
implicit declaration of function âfooâ"! What happened?

I'm using:

gcc (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010

Ubuntu clang version 3.6.2-1 (tags/RELEASE_362/final) (based on LLVM 3.6.2)
Target: x86_64-pc-linux-gnu
Thread model: posix

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]