Implement rule 28-6-1, only move non-const lvalues#992
Implement rule 28-6-1, only move non-const lvalues#992MichaelRFairhurst wants to merge 7 commits intomainfrom
Conversation
|
This PR is basically done and ready to be reviewed. However, this seems like it should be part of coding-standards-cpp-baseline. It has very few findings, and the findings can be fairly serious (moving a const lvalue is definitely an alarming finding). |
There was a problem hiding this comment.
Pull request overview
This PR implements MISRA C++ 2023 rule 28-6-1, which requires that std::move only be called with non-const lvalue arguments. Calling std::move on const lvalues will not result in a move operation, and calling it on rvalues is redundant. The implementation includes a new comprehensive type resolution infrastructure that replaces the previous PossiblySpecified module with a more robust ResolvesTo system that better handles typedefs, decltypes, and CV-qualifiers. Several existing queries have been refactored to use the new type resolution modules.
- Added new query for RULE-28-6-1 with comprehensive test coverage including template instantiations
- Introduced new type resolution modules (
Resolve.qll,Specifiers.qll) and value category handling (ValueCategory.qll) - Refactored 4 existing queries to use the new type resolution infrastructure
Reviewed changes
Copilot reviewed 36 out of 37 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
rules.csv |
Added RULE-28-6-1 mapping to Preconditions5 package |
rule_packages/cpp/Preconditions5.json |
New rule package metadata for RULE-28-6-1 |
cpp/misra/test/rules/RULE-28-6-1/test.cpp |
Comprehensive test cases covering const/non-const lvalues, rvalues, and template scenarios |
cpp/misra/test/rules/RULE-28-6-1/StdMoveWithNonConstLvalue.expected |
Expected query results for 21 non-compliant std::move calls |
cpp/misra/test/rules/RULE-28-6-1/StdMoveWithNonConstLvalue.qlref |
Query reference for test execution |
cpp/misra/src/rules/RULE-28-6-1/StdMoveWithNonConstLvalue.ql |
Query implementation detecting improper std::move usage |
cpp/common/src/codingstandards/cpp/types/Resolve.qll |
New comprehensive type resolution module supporting typedef/decltype resolution and specifier handling |
cpp/common/src/codingstandards/cpp/types/Specifiers.qll |
New module for handling const/volatile specifiers |
cpp/common/src/codingstandards/cpp/types/Type.qll |
Removed deprecated PossiblySpecified module |
cpp/common/src/codingstandards/cpp/ast/ValueCategory.qll |
New module for determining expression value categories (lvalue/prvalue/xvalue) |
cpp/misra/src/rules/RULE-9-5-1/LegacyForStatementsShouldBeSimple.ql |
Refactored to use new type resolution for pointer/reference type checking |
c/misra/src/rules/RULE-22-12/NonstandardUseOfThreadingObject.ql |
Updated to use ResolvesTo for threading object type detection |
c/misra/src/rules/RULE-22-13/ThreadingObjectWithInvalidStorageDuration.ql |
Updated to use ResolvesTo for threading object type detection |
c/misra/src/rules/RULE-22-14/MutexNotInitializedBeforeUse.ql |
Updated to use ResolvesTo for mutex/condition type detection |
c/cert/src/rules/INT36-C/ConvertingAPointerToIntegerOrIntegerToPointer.ql |
Refactored to use new type resolution for int/pointer type comparisons |
cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll |
Added Preconditions5 package metadata integration |
cpp/common/src/codingstandards/cpp/exclusions/cpp/Preconditions5.qll |
Generated exclusion metadata for RULE-28-6-1 |
cpp/common/test/library/codingstandards/cpp/types/Resolve/test.cpp |
Library tests for type resolution with 42 test cases |
cpp/common/test/library/codingstandards/cpp/types/Resolve/ResolveTest.ql |
Test query for validating type resolution functionality |
change_notes/2025-12-03-type-resolution-tracking-changes.md |
Change notes documenting the type resolution refactoring impact |
Multiple codeql-pack.lock.yml files |
Added qtil 0.0.3 dependency across all packages |
cpp/common/src/qlpack.yml |
Added qtil 0.0.3 dependency declaration |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| std::string &&l5 = std::string{"hello"}; | ||
| const std::string &&l6 = std::string{"hello"}; | ||
|
|
||
| func(std::move(l1)); // COMPLIANT - non-const lvalue |
There was a problem hiding this comment.
I wonder why wrapping std::move calls with func(...) is needed?
There was a problem hiding this comment.
Tests in general have been both cleaned up, and expanded.
fe35192 to
45a7ecc
Compare
|
Rebased to remove dependency on #991 |
Description
Implement 28-6-1, std::move with const will not move, and std::move with a non-lvalue is redundant.
Unfortunately,
expr.getLvalueCategory()did not work out of the box, as it generates extra rvalue for load steps that are transparent to the user, so we have to navigate lvalue to rvalue conversion etc to handle properly.isLvalue()also exists, but its an incomplete syntactic match. Further, the definition of an lvalue/xvalue/etc changes across C++ versions, which that function doesn't handle. While MISRA C++ 2023 currently requires C++17, we want our queries to work for users that don't comply with that restriction, for instance, users using the next version of MISRA C++ :)Change request type
.ql,.qll,.qlsor unit tests)Rules with added or modified queries
RULE-28-6-1Release 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.