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
GCC's -Wstrict-prototypes warning not implemented in Clang #21170
Comments
A better example would have been a function declaration rather than a definition: void foo(); // foo()'s arguments are unspecified because, in C (but not C++), it is semantically different from: void foo(void); // foo() takes no arguments I enabled this warning for NaCl code because it catches the occasional bug where functions are called with the wrong number of arguments (see https://code.google.com/p/nativeclient/issues/detail?id=3114). |
You can get something similar from -Wmissing-prototypes: :1:18: warning: no previous prototype for function 'foo' [-Wmissing-prototypes] |
-Wmissing-prototypes warns about things that -Wstrict-prototypes doesn't, that I'm not interested in, like this: void bar(void) { } /* Without declaration before */ Also, -Wmissing-prototypes fails to warn about things that are problematic, such as this: void (*func_ptr)(); BTW, I filed this issue because thakis@chromium.org asked me to (in https://codereview.chromium.org/508823007/). |
Here's a bunch of test cases. Anything interesting that's missing? $ cat test/Sema/warn-strict-prototypes.c void foo0(); // expected-warning{{function declaration isn’t a prototype}} void foo0() {} // expected-warning{{function declaration isn’t a prototype}} void (*foo2)(); // expected-warning{{function declaration isn’t a prototype}} void foo4(int a) {} // FIXME: test this doesn't get a note with a fixme, while the rest does |
Maybe this too: void foo4(int a) { |
The last one is annoying: // RUN: %clang_cc1 -fsyntax-only -Wstrict-prototypes -verify %s void foo0(); // expected-warning{{function declaration isn’t a prototype}} void foo0() {} // expected-warning{{function declaration isn’t a prototype}} void (*foo2)(); // expected-warning{{function declaration isn’t a prototype}} void foo4(int a) { // FIXME: test this doesn't get a note with a fixme, while the rest does void foo6(int p, int p2); |
If it weren't for that last case, this would do it: Nicos-MacBook-Pro:clang thakis$ svn diff lib/Sema/SemaType.cpp
|
Why should this warn? Per 6.7.5.3/12: "An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters." |
Maybe I'm missing something; could you not emit the warning in all cases, and only emit the fixit if there's no declared parameters? |
I believe this bug is very valid, and the warning should indeed be implemented and even enabled by default. This situation applies to the blocks extension as well, and many Objective-C codebases use () when they mean to use (void), thinking the former means no parameters. Examples: |
I've proposed a patch for the issue here: http://reviews.llvm.org/D16533 |
I committed the fix in r288896. |
Extended Description
"-Wstrict-prototypes" appears to be a no-op in Clang.
$ cat strict_protos.c
void foo() {
}
$ gcc -c strict_protos.c -Wstrict-prototypes
strict_protos.c:2:6: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
void foo() {
^
Using Chromium's build of Clang:
$ .../third_party/llvm-build/Release+Asserts/bin/clang -c strict_protos.c -Wstrict-prototypes
$ .../third_party/llvm-build/Release+Asserts/bin/clang --version
clang version 3.5.0 (trunk 209387)
Target: x86_64-unknown-linux-gnu
Thread model: posix
The text was updated successfully, but these errors were encountered: