CRITICAL
Rule Definition
The copy operation of an 'auto_ptr' is destructive (copying A to B changes the state of A)As a result, 'std::auto_ptr' should not be used.
Remediation
Do not use 'auto_ptr'. Instead, use collections of 'std::unique_ptr' if your compiler supports C++11, or of a 'shared_ptr' type, such as 'std::shared_ptr', 'std::tr1::shared_ptr' or 'boost::shared_ptr', depending on what you have available.
Violation Code Sample
void f()
{
std::vector<std::auto_ptr<Widget>> v;
}
Fixed Code Sample
void f()
{
std::vector<std::unique_ptr<Widget>> v;
}
Related Technologies
Technical Criterion
Programming Practices - Unexpected Behavior
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.