Skip to content

Commit 9dbc39f

Browse files
committed
Rule 7.0.6: Clarify pass-by-value on parameters
1 parent acfb253 commit 9dbc39f

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

cpp/misra/src/rules/RULE-7-0-6/NumericAssignmentTypeMismatch.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ predicate isAssignment(Expr source, NumericType targetType, string context) {
101101
context = "initialization"
102102
)
103103
or
104+
// Passing a function parameter by value
104105
exists(Call call, int i |
105106
call.getArgument(i) = source and
106107
not targetType.stripTopLevelSpecifiers() instanceof ReferenceType and

cpp/misra/test/rules/RULE-7-0-6/test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,12 @@ void f13(std::uint16_t &l1) {}
351351

352352
void f14(std::uint32_t l1) {}
353353

354-
void test_references() {
354+
void test_references_to_parameters() {
355355
std::uint8_t l1 = 42;
356356
std::uint16_t l2 = 1000;
357357

358-
f13(l1); // COMPLIANT - exact match
359-
f13(l2); // COMPLIANT - exact match
358+
f13(l1); // COMPLIANT - not covered by rule, as pass-by-ref
359+
f13(l2); // COMPLIANT - not covered by rule, as pass-by-ref
360360

361361
std::uint16_t &l3 = l2;
362362
f14(l3); // NON_COMPLIANT - must be the same type, as non-overload-independent

0 commit comments

Comments
 (0)