Skip to content

Commit 612c635

Browse files
committed
Exclude enums that implement the BitmaskType trait
1 parent 82e1f1c commit 612c635

File tree

1 file changed

+28
-0
lines changed
  • cpp/common/src/codingstandards/cpp

1 file changed

+28
-0
lines changed

cpp/common/src/codingstandards/cpp/Type.qll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,31 @@ Type stripSpecifiers(Type type) {
5959
then result = stripSpecifiers(type.(SpecifiedType).getBaseType())
6060
else result = type
6161
}
62+
63+
/**
64+
* A type that implements the BitmaskType trait.
65+
* https://en.cppreference.com/w/cpp/named_req/BitmaskType
66+
*/
67+
abstract class BitmaskType extends Type { }
68+
69+
/**
70+
* Holds if `enum` implements required overload `overload` to implement
71+
* the BitmaskType trait.
72+
*/
73+
private predicate isRequiredEnumOverload(Enum enum, Function overload) {
74+
overload.getName().regexpMatch("operator([&|^~]|&=|\\|=)") and
75+
forex(Parameter p | p = overload.getAParameter() |
76+
(
77+
p.getType() = enum
78+
or
79+
p.getType().(ReferenceType).getBaseType() = enum
80+
)
81+
)
82+
}
83+
84+
private class EnumBitmaskType extends BitmaskType, Enum {
85+
EnumBitmaskType() {
86+
// Implements all the required overload
87+
count(Function overload | isRequiredEnumOverload(this, overload)) = 6
88+
}
89+
}

0 commit comments

Comments
 (0)