-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clang's -Wdeprecated-non-prototype warning points at the wrong line #60592
Comments
The situation you point out is a false negative that we miss (where The reasoning behind the current behavior is that the function with a prototype is the preferred approach and the function without the prototype is what should be warned on because that's the functionality that's changing (in addition to already being deprecated). The suggestion here is to reverse that logic and warn about the preferred approach. (NB -- I have no data one way or the other that users are more likely to change code labeled with a warning vs code labeled with a note. It'd be interesting if we could get any data about this. CC @cjdb as this sort of relates to the diagnostic improvement work he's been looking into.) The way the diagnostic works in this case is that we have to see the conflicting declaration and definition to know there's a problem. (Otherwise, the user could be doing So:
is by careful design intended to reduce the false positive rate of the diagnostic. If the goal is "warn me about any declaration of a function without a prototype", then |
@llvm/issue-subscribers-c |
You are arguing with concepts of the past. If the goal of the warning was to provide safe code for C17, I would agree with you. But the warning option
Here you are assuming that the programmer has not done the migration from K&R C code to code with prototypes in 33 years. That is one possibility; but the other possibility is that they have done this migration already, and they have left-over unused arguments in the In other words, you are trying to predict which of two elements of the conflict is the one the programmer will want to change. 1. It's not clear that your prediction is correct more than 50% of the time. 2. Programmers usually consider both the 'warning:' line and the 'note:' lines before deciding which one to edit/correct. |
Exactly. In C17 and before, that code was valid. In C23, it's no longer valid. The definition provides strictly more information than the declaration does, so the most likely fix for a user who needs to migrate from C17 to C23 is to fix the declaration, not the definition. Hence we warn on the declaration.
Sadly, longer than that. It was deprecated in 1978 with K&R C 2nd edition. But that assumption is not unfounded, as a rather public example shows: madler/zlib#633 (comment) Further, there's a lot of unmaintained C code in various distro packages that needs to keep working, etc. At the end of the day, I'm still not certain there's a path forward to warn about the declaration in |
Closing this as not a bug because it's behaving by design, and I don't think Clang's behavior is going to change in this area. However, if you disagree, feel free to reopen the issue with more information so we can continue the discussion. |
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
:Put this in
foo1.c
:Put this in
foo2.c
:Compile
foo1.c
andfoo2.c
:Suggested fix:
The text was updated successfully, but these errors were encountered: