Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- `RULE-6-4-2` - `InheritedOverridableMemberFunction.ql`:
Comment thread
mbaluda marked this conversation as resolved.
- Improved evaluation performance.
Comment thread
mbaluda marked this conversation as resolved.
- `RULE-6-9-2` - `AvoidStandardIntegerTypeNames.ql`:
- Fixed query name.
- `RULE-7-0-4` - `InappropriateBitwiseOrShiftOperands.ql`:
- Improved evaluation performance.
- Removed false positives related to the `insertion operator`.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,24 @@ abstract class HiddenInheritedOverridableMemberFunctionSharedQuery extends Query

Query getQuery() { result instanceof HiddenInheritedOverridableMemberFunctionSharedQuery }

private class OverridingDeclaration extends FunctionDeclarationEntry {
OverridingDeclaration() { this.getDeclaration().hasDefinition() implies not this.isDefinition() }
}

private class HiddenDeclaration extends OverridingDeclaration {
HiddenDeclaration() {
// Check if we are overriding a virtual inherited member function
this.getDeclaration().isVirtual() and
// Exclude private member functions, which cannot be inherited.
Comment thread
mbaluda marked this conversation as resolved.
not this.getDeclaration().(MemberFunction).isPrivate()
}
}

query predicate problems(
FunctionDeclarationEntry overridingDecl, string message, FunctionDeclarationEntry hiddenDecl,
OverridingDeclaration overridingDecl, string message, HiddenDeclaration hiddenDecl,
string hiddenDecl_string
) {
Comment on lines +29 to 31
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

problems is a public query predicate, but its parameters are now typed as OverridingDeclaration/HiddenDeclaration, which are declared private in this module. That effectively makes problems hard/impossible to call from other modules (they cannot name these types) and is inconsistent with other shared-query libraries that keep public signatures in terms of public CodeQL types. Consider either making these classes non-private, or keeping the problems signature in terms of FunctionDeclarationEntry and moving the extra constraints into helper predicates/classes used internally.

Suggested change
OverridingDeclaration overridingDecl, string message, HiddenDeclaration hiddenDecl,
string hiddenDecl_string
) {
FunctionDeclarationEntry overridingDecl, string message,
FunctionDeclarationEntry hiddenDecl, string hiddenDecl_string
) {
overridingDecl instanceof OverridingDeclaration and
hiddenDecl instanceof HiddenDeclaration and

Copilot uses AI. Check for mistakes.
not isExcluded(overridingDecl, getQuery()) and
// Check if we are overriding a virtual inherited member function
hiddenDecl.getDeclaration().isVirtual() and
// Exclude private member functions, which cannot be inherited.
not hiddenDecl.getDeclaration().(MemberFunction).isPrivate() and
// The overriding declaration hides the hidden declaration if:
(
// 1. the overriding declaration overrides a function in a base class that is an overload of the hidden declaration
Expand All @@ -46,9 +55,6 @@ query predicate problems(
overridingDecl.getDeclaration().getDeclaringType().getABaseClass() =
hiddenDecl.getDeclaration().getDeclaringType()
) and
// Limit the results to the declarations and not the definitions, if any.
(overridingDecl.getDeclaration().hasDefinition() implies not overridingDecl.isDefinition()) and
(hiddenDecl.getDeclaration().hasDefinition() implies not hiddenDecl.isDefinition()) and
message =
"Declaration for member '" + overridingDecl.getName() +
"' hides overridable inherited member function $@" and
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @id cpp/misra/avoid-standard-integer-type-names
* @name RULE-6-9-2: The names of the standard signed integer types and standard unsigned integer types should not be
* @name RULE-6-9-2: The names of the standard integer types should not be used
* @description Using standard signed and unsigned integer type names instead of specified width
* types makes storage requirements unclear and implementation-dependent.
* @kind problem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ predicate isConstantExpression(Expr e) {
e.isConstant()
}

predicate isValidShiftConstantRange(Expr right, Type leftType) {
bindingset[right, leftType]
pragma[inline_late]
Comment thread
mbaluda marked this conversation as resolved.
predicate isValidShiftConstantRange(Expr right, MisraCpp23BuiltInTypes::NumericType leftType) {
exists(int value |
value = right.getValue().toInt() and
value >= 0 and
value < leftType.getSize() * 8
value < leftType.getBuiltInSize() * 8
Comment thread
mbaluda marked this conversation as resolved.
Outdated
)
}
Comment thread
mbaluda marked this conversation as resolved.

Expand Down Expand Up @@ -97,7 +99,10 @@ where
)
or
// Shift operators - right operand must be unsigned or constant in valid range
exists(BinaryShiftOpOrAssignOp shift, Expr right, Type rightType, Type leftType |
exists(
BinaryShiftOpOrAssignOp shift, Expr right, Type rightType,
MisraCpp23BuiltInTypes::NumericType leftType
|
right = shift.getRightOperand() and
x = right and
rightType = right.getExplicitlyConverted().getType() and
Expand All @@ -108,7 +113,7 @@ where
not isValidShiftConstantRange(right, leftType) and
message =
"Shift operator '" + shift.getOperator() + "' shifts by " + right.getValue().toInt() +
" which is not within the valid range 0.." + ((leftType.getSize() * 8) - 1) + "."
" which is not within the valid range 0.." + ((leftType.getBuiltInSize() * 8) - 1) + "."
else (
not MisraCpp23BuiltInTypes::isUnsignedType(rightType) and
message =
Expand Down
2 changes: 1 addition & 1 deletion rule_packages/cpp/BannedAPIs.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
{
"description": "Using standard signed and unsigned integer type names instead of specified width types makes storage requirements unclear and implementation-dependent.",
"kind": "problem",
"name": "The names of the standard signed integer types and standard unsigned integer types should not be",
"name": "The names of the standard integer types should not be used",
"precision": "very-high",
"severity": "error",
"short_name": "AvoidStandardIntegerTypeNames",
Comment thread
mbaluda marked this conversation as resolved.
Expand Down
Loading