MISRA Discussion Forums

Full Version: Rule 22.1: object declaration and deleted timing
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I have a question about object declaration and deleted timing.
I need to declare an object in constructor and release it in deconstructor, because the object will be reused frequently, but it is not compliant on MISRA C 2012.
The sample code as below.
Could you give me any hint to solve it?
Thanks.

Code:
ABC::aa(const Arguments& args)
{
    pImpl = new ABC::impl(args);
}

ABC::~aa()
{
    delete pImpl;
    pImpl = NULL;
}
The above code is a violation of rule 1.1.
Quote: The program shall contain no violation of the standard C syntax ....
MISRA C:2012 is not applicable to C++ code. Such code should be analysed against the MISRA C++:2008 guidelines.