Skip to content

Commit 304479c

Browse files
committed
Make a base class OperatorNewOrDelete and use that in 21-6-3
1 parent 466eb52 commit 304479c

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

cpp/common/src/codingstandards/cpp/allocations/CustomOperatorNewDelete.qll

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,21 @@ class ConstNoThrowTReferenceType extends ReferenceType {
1414
}
1515

1616
/** An `operator` that implements one of the `[replacement.functions]`. */
17-
abstract class CustomOperatorNewOrDelete extends Operator {
17+
abstract class OperatorNewOrDelete extends Operator {
18+
OperatorNewOrDelete() {
19+
this.getName().regexpMatch("operator new(\\[\\])?") or
20+
this.getName().regexpMatch("operator delete(\\[\\])?")
21+
}
22+
}
23+
24+
/** An `operator` that implements one of the `[replacement.functions]`. */
25+
abstract class CustomOperatorNewOrDelete extends OperatorNewOrDelete {
1826
CustomOperatorNewOrDelete() {
1927
// Not in the standard library
2028
exists(getFile().getRelativePath()) and
2129
// Not in a file called `new`, which is likely to be a copy of the standard library
2230
// as it is in our tests
23-
not forall(File file | file = this.getADeclarationLocation().getFile() |
24-
file.getBaseName() = "new"
25-
) and
26-
(
27-
this.getName().regexpMatch("operator new(\\[\\])?") or
28-
this.getName().regexpMatch("operator delete(\\[\\])?")
29-
)
31+
not getFile().getBaseName() = "new"
3032
}
3133

3234
/**

cpp/misra/src/rules/RULE-21-6-3/AdvancedMemoryManagementUsed.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class AdvancedMemoryManagementFunction extends Function {
3535
string describe() { result = description }
3636
}
3737

38-
class NonStandardNewOrNewArrayOperator extends CustomOperatorNewOrDelete {
38+
class NonStandardNewOrNewArrayOperator extends OperatorNewOrDelete {
3939
NonStandardNewOrNewArrayOperator() {
4040
this.getName() in ["operator new", "operator new[]"] and
4141
not this instanceof CustomOperatorNew // `CustomOperatorNew` only detects replaceable allocation functions.
@@ -61,7 +61,7 @@ class UserDeclaredOperatorNewOrDelete extends FunctionDeclarationEntry {
6161
}
6262
}
6363

64-
class NonStandardDeleteOrDeleteArrayOperator extends CustomOperatorNewOrDelete {
64+
class NonStandardDeleteOrDeleteArrayOperator extends OperatorNewOrDelete {
6565
NonStandardDeleteOrDeleteArrayOperator() {
6666
this.getName() in ["operator delete", "operator delete[]"] and
6767
not this instanceof CustomOperatorDelete // `CustomOperatorDelete` only detects replaceable deallocation functions.

0 commit comments

Comments
 (0)