@@ -21,70 +21,73 @@ abstract class OperatorNewOrDelete extends Operator {
2121 }
2222}
2323
24- /** An `operator` that implements one of the `[replacement.functions]`. */
25- abstract class CustomOperatorNewOrDelete extends OperatorNewOrDelete {
24+ class ReplaceableOperatorNew extends OperatorNewOrDelete {
25+ ReplaceableOperatorNew ( ) {
26+ this .getName ( ) .regexpMatch ( "operator new(\\[\\])?" ) and
27+ this .getParameter ( 0 ) .getType ( ) instanceof Size_t and
28+ (
29+ this .getNumberOfParameters ( ) = 1
30+ or
31+ this .getNumberOfParameters ( ) = 2 and
32+ this .getParameter ( 1 ) .getType ( ) instanceof ConstNoThrowTReferenceType
33+ )
34+ }
35+ }
36+
37+ class CustomOperatorNewOrDelete extends OperatorNewOrDelete {
2638 CustomOperatorNewOrDelete ( ) {
39+ this .hasDefinition ( ) and
2740 // Not in the standard library
28- exists ( getFile ( ) .getRelativePath ( ) ) and
41+ exists ( this . getFile ( ) .getRelativePath ( ) ) and
2942 // Not in a file called `new`, which is likely to be a copy of the standard library
3043 // as it is in our tests
31- not getFile ( ) .getBaseName ( ) = "new"
44+ not this . getFile ( ) .getBaseName ( ) = "new"
3245 }
3346
3447 /**
3548 * Holds if this is a an allocation function that takes a `const std::nothrow_t&`.
3649 */
3750 predicate isNoThrowAllocation ( ) {
38- getAParameter ( ) .getType ( ) instanceof ConstNoThrowTReferenceType
51+ this . getAParameter ( ) .getType ( ) instanceof ConstNoThrowTReferenceType
3952 }
4053
4154 /** Get the description of this custom allocator. */
4255 string getAllocDescription ( ) {
4356 result =
44- getName ( ) + "(" +
45- concat ( Parameter p , int i | p = getParameter ( i ) | p .getType ( ) .getName ( ) , "," order by i ) +
46- ")"
57+ this . getName ( ) + "(" +
58+ concat ( Parameter p , int i | p = this . getParameter ( i ) | p .getType ( ) .getName ( ) , "," order by i )
59+ + ")"
4760 }
4861}
4962
50- class CustomOperatorNew extends CustomOperatorNewOrDelete {
51- CustomOperatorNew ( ) {
52- hasDefinition ( ) and
53- getName ( ) .regexpMatch ( "operator new(\\[\\])?" ) and
54- getParameter ( 0 ) .getType ( ) instanceof Size_t and
55- (
56- getNumberOfParameters ( ) = 1
57- or
58- getNumberOfParameters ( ) = 2 and
59- getParameter ( 1 ) .getType ( ) instanceof ConstNoThrowTReferenceType
60- )
61- }
62- }
63+ class CustomReplaceableOperatorNew extends CustomOperatorNewOrDelete , ReplaceableOperatorNew { }
6364
64- class CustomOperatorDelete extends CustomOperatorNewOrDelete {
65- CustomOperatorDelete ( ) {
66- getName ( ) .regexpMatch ( "operator delete(\\[\\])?" ) and
67- getParameter ( 0 ) .getType ( ) instanceof VoidPointerType and
65+ class ReplaceableOperatorDelete extends OperatorNewOrDelete {
66+ ReplaceableOperatorDelete ( ) {
67+ this . getName ( ) .regexpMatch ( "operator delete(\\[\\])?" ) and
68+ this . getParameter ( 0 ) .getType ( ) instanceof VoidPointerType and
6869 (
69- getNumberOfParameters ( ) = 1
70+ this . getNumberOfParameters ( ) = 1
7071 or
71- getNumberOfParameters ( ) = 2 and
72+ this . getNumberOfParameters ( ) = 2 and
7273 (
73- getParameter ( 1 ) .getType ( ) instanceof ConstNoThrowTReferenceType
74+ this . getParameter ( 1 ) .getType ( ) instanceof ConstNoThrowTReferenceType
7475 or
75- getParameter ( 1 ) .getType ( ) instanceof Size_t
76+ this . getParameter ( 1 ) .getType ( ) instanceof Size_t
7677 )
7778 or
78- getNumberOfParameters ( ) = 3 and
79+ this . getNumberOfParameters ( ) = 3 and
7980 (
80- getParameter ( 1 ) .getType ( ) instanceof Size_t and
81- getParameter ( 2 ) .getType ( ) instanceof ConstNoThrowTReferenceType
81+ this . getParameter ( 1 ) .getType ( ) instanceof Size_t and
82+ this . getParameter ( 2 ) .getType ( ) instanceof ConstNoThrowTReferenceType
8283 )
8384 )
8485 }
86+ }
8587
86- CustomOperatorDelete getPartner ( ) {
87- if getAParameter ( ) .getType ( ) instanceof Size_t
88+ class CustomReplaceableOperatorDelete extends CustomOperatorNewOrDelete , ReplaceableOperatorDelete {
89+ CustomReplaceableOperatorDelete getPartner ( ) {
90+ if this .getAParameter ( ) .getType ( ) instanceof Size_t
8891 then
8992 result .getAllocDescription ( ) = this .getAllocDescription ( ) .replaceAll ( ",size_t" , "" ) and
9093 // Linked together in the same target
0 commit comments