Skip to content

clang's -Wdeprecated-non-prototype warning points at the wrong line #60592

Closed as not planned
@bhaible

Description

@bhaible

Clang's -Wdeprecated-non-prototype warning can warn about a conflict between a function declaration and the definition of the same function. That's good.

When warning about a conflict, using the current style with "warning: ..." and "note: ...", one of the two lines must be mentioned in the "warning", and the other one in the "note".

Unfortunately, Clang's choice to put the function declaration in the "warning" line and the function definition in the "note" line has a silly effect: The same header file, included by two different compilation units, shows a warning in one compilation unit but not in the other compilation unit.

How to reproduce (with Clang 15.0.6):
Put this in foo.h:

void func3 ();

Put this in foo1.c:

#include "foo.h"
void func3 (int x, int y) {}

Put this in foo2.c:

#include "foo.h"

Compile foo1.c and foo2.c:

$ clang -S -Wdeprecated-non-prototype foo1.c
In file included from foo1.c:1:
./foo.h:1:6: warning: a function declaration without a prototype is deprecated in all versions of C and is treated as a zero-parameter prototype in C2x, conflicting with a subsequent definition [-Wdeprecated-non-prototype]
void func3 ();
     ^
foo1.c:2:6: note: conflicting prototype is here
void func3 (int x, int y) {}
     ^
1 warning generated.
$ clang -S -Wdeprecated-non-prototype foo2.c

Suggested fix:

$ clang -S -Wdeprecated-non-prototype foo1.c
foo1.c:2:6: warning: function definition conflicts with previous non-prototype declaration that will be treated like a zero-parameter prototype in C2x [-Wdeprecated-non-prototype]
void func3 (int x, int y) {}
     ^
In file included from foo1.c:1:
./foo.h:1:6: note: conflicting function declaration is here
void func3 ();
     ^
1 warning generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cclang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerinvalidResolved as invalid, i.e. not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions