https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111769
Bug ID: 111769 Summary: Annotate function definitions and calls to facilitate link-time checking Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: david at westcontrol dot com Target Milestone: --- This is an enhancement idea, rather than a bug, and would require linker support as well as compiler support. In C, it is possible to define a function with one set of parameters (number and type) in one translation unit, and declare and use it with a different set in a different translation unit. This is undefined behaviour, and generally a really bad idea, but it can't be spotted by the toolchain unless you use LTO. In C++, you don't see the same effect as different name mangling would result in linker failures. Would it be possible for the C compiler, when emitting an external linkage function definition and the use (or possibly declaration) of a function (for calling or taking its address), to add a directive or debug info section entry giving the function type in active use? These could then be checked at link time, even without LTO, to catch mismatches. My suggestion would be to use the existing C++ name-mangling scheme to encode the function types. Thus the declaration and definition of "int square(int num)" would be annotated with a note that the function "square" has signature "_Z6squarei".