-
Notifications
You must be signed in to change notification settings - Fork 66
A5-2-2: Exclude results in uninstantiated templates, explain limitations #160
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
A5-2-2: Exclude results in uninstantiated templates, explain limitations #160
Conversation
Clarify what `CStyleCast` does and does not cover by adding a comment, expanding the test case and providing an implementation scope. In addition, exclude casts on template parameters to avoid unnecessary false positives.
Any cast in an uninstantiated template that is related to the template parameter may be converted to a `ConstructorCall` when the template is instantiated. To avoid the common false positive case where the functional cast notation is used to call a constructor, we exclude all results in uninstantiated templates and instead rely on reporting results in template instantiations instead.
Note for author and reviewer: https://en.cppreference.com/w/cpp/language/explicit_cast Take a look at the "Ambiguity Resolution" section -- there are some interesting cases that look probable. |
These are good examples to test the extractor but do not seem directly useful for this query. |
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.
LGTM
🤖 Beep Boop! Matrix Testing for this PR has been initiated. Please check back later for results. |
🤖 Beep Boop! gcc/c/x86_64 Matrix Testing for this PR has been completed but I didn't find anything to test! |
🤖 Beep Boop! clang/c/x86_64 Matrix Testing for this PR has been completed but I didn't find anything to test! |
🤖 Beep Boop! Matrix Testing for this PR has been initiated. Please check back later for results. |
🤖 Beep Boop! clang/cpp/x86_64 Matrix Testing for this PR has been completed. See below for the results!
|
🤖 Beep Boop! clang/c/x86_64 Matrix Testing for this PR has been completed but I didn't find anything to test! |
🤖 Beep Boop! gcc/c/x86_64 Matrix Testing for this PR has been completed but I didn't find anything to test! |
🤖 Beep Boop! gcc/cpp/x86_64 Matrix Testing for this PR has been completed. See below for the results!
|
🤖 Beep Boop! clang/cpp/x86_64 Matrix Testing for this PR has been completed. See below for the results!
|
🤖 Beep Boop! gcc/cpp/x86_64 Matrix Testing for this PR has been completed. See below for the results!
|
🤖 Beep Boop! Matrix Testing for this PR has been completed. If no reports were posted it means this PR does not contain things that need matrix testing! |
1 similar comment
🤖 Beep Boop! Matrix Testing for this PR has been completed. If no reports were posted it means this PR does not contain things that need matrix testing! |
🤖 Beep Boop! Matrix Testing for this PR has been initiated. Please check back later for results. |
🤖 Beep Boop! gcc/c/x86_64 Matrix Testing for this PR has been completed but I didn't find anything to test! |
🤖 Beep Boop! clang/c/x86_64 Matrix Testing for this PR has been completed but I didn't find anything to test! |
🤖 Beep Boop! clang/cpp/x86_64 Matrix Testing for this PR has been completed. See below for the results!
|
🤖 Beep Boop! gcc/cpp/x86_64 Matrix Testing for this PR has been completed. See below for the results!
|
🤖 Beep Boop! Matrix Testing for this PR has been completed. If no reports were posted it means this PR does not contain things that need matrix testing! |
Description
The scope of this rule is intended to be so-called "c-style" casts. Unfortunately, our query for this rule has both false positives and false negatives due the way such casts are modelled in CodeQL.
Firstly, the
CStyleCast
CodeQL class includes "function notation" casts such as:I don't believe these are intended to part of the AUTOSAR rule, as they are not legal C casts, and therefore I don't think they count as "C-Style". Furthermore, the distinction is lost at the database schema level, so there's no universal query-level approach to distinguish between c-style and functional notation casts.
Secondly, if a c-style (or functional notation) cast results in a constructor call to a single argument constructor, the
CStyleCast
is not added to the database, and instead is replaced with the directConstructorCall
. Again, at a database schema level, there is no universal way to determine if a particular constructor call was created from a cast, as the information has been lost.As a consequence this query:
ConstructorCall
e.g. when the argument type is compatible with a single-argument constructor.This PR:
implementation_scope
.T(x)
, and where in the instantiation the cast will be replaced with aConstructorCall
and therefore not reported. In practice, I believe this will remove the most common cause of false positives.Change request type
.ql
,.qll
,.qls
or unit tests)Rules with added or modified queries
A5-2-2
Release change checklist
A change note (development_handbook.md#change-notes) is required for any pull request which modifies:
If you are only adding new rule queries, a change note is not required.
Author: Is a change note required?
🚨🚨🚨
Reviewer: Confirm that format of shared queries (not the .qll file, the
.ql file that imports it) is valid by running them within VS Code.
Reviewer: Confirm that either a change note is not required or the change note is required and has been added.
Query development review checklist
For PRs that add new queries or modify existing queries, the following checklist should be completed by both the author and reviewer:
Author
As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.
Reviewer
As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.