Skip to content

Commit 2d14c81

Browse files
committed
Fix CanonicalIntegralType classes
1 parent f7cd25e commit 2d14c81

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

cpp/common/src/codingstandards/cpp/types/CanonicalTypes.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ class CanonicalIntegralType extends IntegralType {
1212
predicate isMinimal() {
1313
not exists(CanonicalIntegralType other |
1414
other.getSize() = this.getSize() and
15+
(
16+
other.isSigned() and this.isSigned()
17+
or
18+
other.isUnsigned() and this.isUnsigned()
19+
) and
1520
other.getName().length() < this.getName().length()
1621
)
1722
}

cpp/misra/src/codingstandards/cpp/misra/BuiltInTypeRules.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,16 @@ predicate isUnsignedType(NumericType t) { t.getSignedness() = Unsigned() }
148148
* Where multiple canonical arithmetic types exist for a given size/signedness combination, we
149149
* prefer the type with the shortest name.
150150
*/
151-
class CanonicalIntegerNumericType extends NumericType, CanonicalIntegralType {
151+
class CanonicalIntegerNumericType extends NumericType {
152152
CanonicalIntegerNumericType() {
153153
// Where multiple types exist with the same size and signedness, prefer shorter names - mainly
154154
// to disambiguate between `unsigned long` and `unsigned long long` on platforms where they
155155
// are the same size
156-
this.isMinimal()
156+
this.(CanonicalIntegralType).isMinimal()
157+
or
158+
// `signed char` is not considered a canonical type (`char` is), but `char` is not a MISRA numeric
159+
// type, so we need to reintroduce `signed char` here.
160+
this instanceof SignedCharType
157161
}
158162
}
159163

0 commit comments

Comments
 (0)