@@ -15,11 +15,29 @@ import cpp
1515import codingstandards.cpp.misra
1616import codingstandards.cpp.SmartPointers
1717
18+ /**
19+ * An `operator new` or `operator new[]` allocation function called by a placement-new expression.
20+ *
21+ * The operator functions are supposed to have a `std::size_t` as their first parameter and a
22+ * `void*` parameter somewhere in the rest of the parameter list.
23+ */
24+ class PlacementNewOrNewArrayAllocationFunction extends AllocationFunction {
25+ PlacementNewOrNewArrayAllocationFunction ( ) {
26+ this .getName ( ) in [ "operator new" , "operator new[]" ] and
27+ this .getParameter ( 0 ) .getType ( ) .resolveTypedefs * ( ) instanceof Size_t and
28+ this .getAParameter ( ) .getUnderlyingType ( ) instanceof VoidPointerType
29+ }
30+ }
31+
1832class DynamicMemoryManagementFunction extends Function {
1933 string description ;
2034
2135 DynamicMemoryManagementFunction ( ) {
22- ( this instanceof AllocationFunction or this instanceof AlignedAlloc ) and
36+ (
37+ ( this instanceof AllocationFunction or this instanceof AlignedAlloc ) and
38+ /* Placement-new expressions are not prohibited by this rule, but by Rule 21.6.3. */
39+ not this instanceof PlacementNewOrNewArrayAllocationFunction
40+ ) and
2341 description = "an expression that dynamically allocates memory"
2442 or
2543 this instanceof DeallocationFunction and
@@ -56,6 +74,9 @@ class AlignedAlloc extends Function {
5674 AlignedAlloc ( ) { this .hasGlobalOrStdName ( "aligned_alloc" ) }
5775}
5876
77+ /**
78+ * The `std::unique_ptr::release` member function.
79+ */
5980class UniquePointerReleaseFunction extends MemberFunction {
6081 UniquePointerReleaseFunction ( ) { this .getClassAndName ( "release" ) instanceof AutosarUniquePointer }
6182}
0 commit comments