Expressions and statements
ES.60
Avoid `new` and `delete` outside resource management functions
Reason
Direct resource management in application code is error-prone and tedious.
Note
This is also known as the rule of "No naked new!"
Example, bad
void f(int n)
{
auto p = new X[n]; // n default constructed Xs
// ...
delete[] p;
}
There can be code in the ... part that causes the delete never to happen.
See also: R: Resource management
Enforcement
Flag naked news and naked deletes.