Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
1d2aa2e
RULE-7-0-1 - NoConversionFromBool
lcartey Jun 10, 2025
5b810c3
Rule 7.0.1: Address review issues
lcartey Jun 10, 2025
62d5dcc
RULE-7-0-2 - NoImplicitBoolConversion
lcartey Jun 11, 2025
f92a2c9
Rule 7.0.2: Extend test case, support member function pointers
lcartey Jun 11, 2025
b62394a
Add Conversions exclusions file
lcartey Jun 12, 2025
a2c9912
RULE-7-0-6 - NumericAssignmentTypeMismatch
lcartey Jun 17, 2025
229705f
Rule 7.0.6: Update test with better variable names
lcartey Jun 17, 2025
f870023
Rule 7.0.6: Fix id-expression detection
lcartey Jun 17, 2025
0ed1689
Rule 7.0.6: Support reference types
lcartey Jun 17, 2025
778b344
Rule 7.0.6: Ignore compound expressions
lcartey Jun 17, 2025
acfb253
Rule 7.0.6: Additional function return test cases
lcartey Jun 17, 2025
9dbc39f
Rule 7.0.6: Clarify pass-by-value on parameters
lcartey Jun 17, 2025
b310e14
Rule 7.0.6: Add user defined operator tests
lcartey Jun 17, 2025
af2ff95
MISRA C++ 2023: Create StandardConversions library
lcartey Jun 17, 2025
ea7d168
MISRA C++ StandardConversions - improve detection of bitfield types
lcartey Jun 17, 2025
5843258
Rule 7.0.6: Improve bitfield support
lcartey Jun 18, 2025
01b517d
StandardConversions: Improve detection of numeric type category
lcartey Jun 18, 2025
06eddfa
Rule 7.0.6: Add a test case for non-numeric (not covered)
lcartey Jun 18, 2025
a65c4cc
StandardConversions: Handle aggregate initialization
lcartey Jun 18, 2025
04613cd
Add a library for determining constant expressions
lcartey Jun 19, 2025
4be1395
Rule 7.0.6: Use BigInt for constant expressions
lcartey Jun 19, 2025
e87892e
Rule 7.0.6: add tests for cv-qualified types
lcartey Jun 19, 2025
916fb3d
Rule 7.0.6: Support pointer to member cases
lcartey Jun 19, 2025
2ec2814
Rule 7.0.6: Support functions with default parameters
lcartey Jun 19, 2025
e659944
Rule 7.0.6: Ignore deleted overloads
lcartey Jun 19, 2025
c0fe44d
Rule 7.0.6: Refactor overload independent code
lcartey Jun 19, 2025
06ffbfb
Rule 7.0.6: Move aggregate tests to new file
lcartey Jun 19, 2025
fc63db1
Rule 7.0.6: Move operator tests to separate file
lcartey Jun 19, 2025
f68658a
Rule 7.0.6: Support constructor field initializers
lcartey Jun 19, 2025
3fdaa98
Rule 7.0.6: Handle explicit conversions
lcartey Jun 19, 2025
063a5cc
Rule 7.0.6: Improve tests for templates
lcartey Jun 20, 2025
96d5c1b
MISRA C++ 2023: Rename StandardConversions library
lcartey Jun 20, 2025
7c5fb87
Rule 7.0.6: Address performance issues
lcartey Jun 20, 2025
6ddab35
Create Call library
lcartey Jun 20, 2025
983f256
Extend ios stubs for C++
lcartey Jun 25, 2025
bb9f5a1
RULE-7-11-3 - FunctionPointerConversionContext
lcartey Jun 25, 2025
2e75310
C++: Improve char_traits stubs
lcartey Jun 25, 2025
4bf8d51
Improve C++ stubs for locales
lcartey Jun 6, 2025
4d5e35f
Extend C++ stubs for locale
lcartey Jun 6, 2025
f2b5410
C++: Add optional stubs
lcartey Jun 25, 2025
74946cf
Rule 7.0.3: NoCharacterNumericalValue.ql
lcartey Jun 25, 2025
a2d7ee3
RULE-7-0-5 - NoSignednessChangeFromPromotion
lcartey Jun 26, 2025
c25057d
Add sizeOfInt() predicate
lcartey Jun 27, 2025
3a8dab1
Rule 7.0.5: Refactor to enable non-Conversions
lcartey Jun 27, 2025
3cf9eac
Improve detection of integer promotions and usual arithmetic conversions
lcartey Jun 27, 2025
f50baa9
Format test case
lcartey Jun 27, 2025
a7ce6f5
Rule 7.0.5: Expand test cases
lcartey Jun 27, 2025
9aed463
Ruley 7.0.5: Support lvalue conversions on assign operations
lcartey Jun 27, 2025
aac2dc2
Refactor to use NumericType
lcartey Jun 27, 2025
92c7dac
Rule 7.0.5: Add pointer tests (should be ignored)
lcartey Jun 27, 2025
4be88a3
Rule 7.0.5: Add failing test case
lcartey Jun 27, 2025
f1502d6
Rule 7.0.5: Add test cases for enum conversions
lcartey Jul 1, 2025
89485d5
Conversions: Swap some queries around
lcartey Jul 1, 2025
6845cdc
RULE-7-0-4 - InappropriateBitwiseOrShiftOperands
lcartey Jul 4, 2025
db58704
Test large and negative constants, use BigInt
lcartey Jul 4, 2025
3d2616a
Rule 7.0.4: Add support for shift-assignment operators
lcartey Jul 7, 2025
05cfc2b
Rule 7.0.5: Add an implementation_scope
lcartey Jul 7, 2025
dd34127
Merge branch 'main' into lcartey/cpp-conversions
lcartey Aug 18, 2025
1cc458b
Rule 7.0.3: Address review feedback
lcartey Aug 18, 2025
51938af
Rule 7.0.1: Address review feedback
lcartey Aug 18, 2025
9bbef6f
Rule 7.0.2: Address review feedback
lcartey Aug 18, 2025
b20ea88
Add a utility library for unifying binary ops
lcartey Aug 19, 2025
3e2534b
Move isSigned/isUnsigned to BuiltInTypes
lcartey Aug 19, 2025
1af908a
Rule 7.0.4: Improve reporting
lcartey Aug 19, 2025
cd8c960
Rule 7.0.6: Correctly handle constructor exception
lcartey Aug 19, 2025
feccaf7
ConstantExpressions: Correct NotExpr to ComplementExpr
lcartey Aug 19, 2025
2c0d06b
Make CanonicalIntegerType singular, use it more widely
lcartey Aug 20, 2025
21cf410
CanonicalTypes: refactor library
lcartey Aug 20, 2025
bc7bf51
Rule 7.0.5: Limit to `Cast`s and refactor naming
lcartey Aug 20, 2025
f7cd25e
BuiltInTypeRules: Handle bit fields in switch cases
lcartey Aug 20, 2025
2d14c81
Fix CanonicalIntegralType classes
lcartey Aug 20, 2025
9ddf645
BuiltInTypeRules: Rename realType to builtInType
lcartey Aug 21, 2025
8be7b3c
BuiltInTypeRules: Add isSameType API
lcartey Aug 21, 2025
bcf8ae9
BuiltInTypeRules: Rename getRealSize to getBuiltInSize
lcartey Aug 21, 2025
94cfcda
MisraType: Avoid misuse of getSize()
lcartey Aug 21, 2025
2c97905
BuiltInTypes: Wrap in MisraCpp23BuiltInTypes module
lcartey Aug 21, 2025
5ca11e9
Add TypeCategory suffix
lcartey Aug 21, 2025
6110770
Update reference to MisraBuiltInTypes
lcartey Aug 21, 2025
8b999e9
BuiltInTypes: Refactor bitfield handling
lcartey Aug 21, 2025
258dadf
Create MISRA arithmetic conversions library
lcartey Aug 21, 2025
3186c70
Test case formatting
lcartey Aug 21, 2025
23be3db
More test case formatting
lcartey Aug 21, 2025
61ae04f
More formatting
lcartey Aug 21, 2025
668e518
Address compilation issue with FunctionType.
lcartey Aug 21, 2025
3575db1
Rule 7.0.2: Use getUnconverted.
lcartey Aug 21, 2025
0b9e2cb
Rule 7.0.2: Treat nullptr_t as a pointer for this rule
lcartey Aug 21, 2025
8d0bb29
Rule 7.0.1: Expand test case to cover non_compliant cases
lcartey Aug 22, 2025
96b644e
Rule 7.0.2: Add extra cast test cases
lcartey Aug 22, 2025
189f8c0
Update expected results after formatting
lcartey Aug 22, 2025
9f46766
Rule 7.0.3: Split unevaluated operands test case
lcartey Aug 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rule 7.0.6: Refactor overload independent code
  • Loading branch information
lcartey committed Jun 19, 2025
commit c0fe44dd335d76c5a790b10a4d588754222b54ca
49 changes: 26 additions & 23 deletions cpp/misra/src/rules/RULE-7-0-6/NumericAssignmentTypeMismatch.ql
Original file line number Diff line number Diff line change
Expand Up @@ -123,34 +123,37 @@ int getMinimumNumberOfParameters(Function f) {
result = count(Parameter p | p = f.getAParameter() and not p.hasInitializer() | p)
}

predicate isOverloadIndependent(Call call, Expr arg) {
arg = call.getAnArgument() and
/** Get an overload of the function f, excluding deleted overloads. */
Function getAnOverload(Function f) {
(
result = f.getAnOverload()
or
// Instantiated function templates don't directly participate in overload resolution
// so check the templates overloads
result = f.(FunctionTemplateInstantiation).getTemplate().getAnOverload()
) and
// Exclude deleted overloads
not result.isDeleted()
}

predicate isOverloadIndependent(Call call, Expr arg) {
exists(int i | arg = call.getArgument(i) |
// Call through function pointer
call instanceof ExprCall
or
isNonExtensible(call) and
forall(Function target, Function overload, int i |
target = call.getTarget() and
(
overload = target.getAnOverload()
or
// Instantiated function templates don't directly participate in overload resolution
// so check the templates overloads
overload = target.(FunctionTemplateInstantiation).getTemplate().getAnOverload()
) and
// Check that the overload accepts the number of arguments provided by this call,
// considering parameters with default values may be omitted in the call
overload.getNumberOfParameters() >= call.getNumberOfArguments() and
getMinimumNumberOfParameters(overload) <= call.getNumberOfArguments() and
// Ignore deleted overloads
not overload.isDeleted() and
//
call.getArgument(i) = arg
|
// Check that the parameter types match
overload.getParameter(i).getType().getUnspecifiedType() =
target.getParameter(i).getType().getUnspecifiedType()
exists(Function target | target = call.getTarget() |
forall(Function overload |
overload = getAnOverload(target) and
// Check that the overload accepts the number of arguments provided by this call,
// considering parameters with default values may be omitted in the call
overload.getNumberOfParameters() >= call.getNumberOfArguments() and
getMinimumNumberOfParameters(overload) <= call.getNumberOfArguments()
|
// Check that the parameter types match
overload.getParameter(i).getType().getUnspecifiedType() =
target.getParameter(i).getType().getUnspecifiedType()
)
)
)
}
Expand Down