-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
C++: Remove FPs from cpp/too-few-arguments #17919
Changes from 3 commits
4d85144
227f9c7
4fa8c6a
60155ce
3b4fdb3
4dab039
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,4 @@ | ||||||
--- | ||||||
category: minorAnalysis | ||||||
--- | ||||||
* The "Call to function with fewer arguments than declared parameters" query (`cpp/too-few-arguments`) query produces no results if the function has been implicitly declared. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
| test.c:34:3:34:19 | call to not_yet_declared2 | This call has fewer arguments than required by $@. | test.c:32:3:32:3 | not_yet_declared2 | not_yet_declared2 | | ||
| test.c:34:3:34:19 | call to not_yet_declared2 | This call has fewer arguments than required by $@. | test.c:76:6:76:22 | not_yet_declared2 | not_yet_declared2 | | ||
Comment on lines
-1
to
-2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| test.c:36:3:36:29 | call to declared_empty_defined_with | This call has fewer arguments than required by $@. | test.c:77:6:77:32 | declared_empty_defined_with | declared_empty_defined_with | | ||
| test.c:87:10:87:20 | call to dereference | This call has fewer arguments than required by $@. | test.c:90:5:90:15 | dereference | dereference | |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,8 +30,8 @@ void test(int *argv[]) { | |
|
||
not_yet_declared1(1); // BAD (GOOD for everything except for cpp/implicit-function-declaration) | ||
not_yet_declared2(1); // BAD (GOOD for everything except for cpp/implicit-function-declaration) | ||
not_yet_declared2(ca); // BAD | ||
not_yet_declared2(); // BAD | ||
not_yet_declared2(ca); // BAD (GOOD for everything except for cpp/mistyped-function-arguments) | ||
calumgrant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
not_yet_declared2(); // GOOD | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think changing this to "GOOD" is incorrect. It's still "BAD", but we no longer detect it. For that we have "BAD [NOT DETECTED]". That probably does need some qualification here, as that only applies to cpp/too-few-arguments. |
||
|
||
declared_empty_defined_with(); // BAD | ||
declared_empty_defined_with(1); // GOOD | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this is too strict, given the test results that disappear. Shouldn't this be something like:
Edit: fixed typos where I wrote "explicit", but meant "implicit", and vice versa.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the scenarios I'd like to handle is something like
file1.c:
file2.c:
In this case, some fndecl entries are explicit, and all explicit fndecls have the same number of parameters.
So I can write
but this basically covers the case above. If we weaken it to
then this doesn't handle the
assert
case above and doesn't get rid of all the noise.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if you move
not f.getADeclarationEntry().isImplicit()
intohasDefiniteNumberOfParameters
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is just to handle
assert
: I would expect there to be some macro definition ofassert
to be in scope. Unless the particular project you're looking at hand-rolled the definition, and we're not managing to pick up on the correct header file?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That didn't remove the FPs. I think it's because implicit
FunctionDeclarationEntry
always have 0 parameters anyway.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The FPs have also appeared on projects that don't involve macros or
assert
. In the case ofassert
, most likely the wrong header file was included or couldn't be found.It would be possible to remove some FPs simply by saying
and not exists(Macro m | m.getName() = f.getName())
but that's very specific and doesn't cover the cases where there isn't a macro involved.In the general case, we'd hope to improve header file resolution, but we should expect this to go wrong at times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. An implicit function declarations
foo
always have the formextern int foo()
.