Rule 22.1: object declaration and deleted timing

Moderators: misra-c, david ward

Post Reply
andy_su
Posts: 1
Joined: Thu Apr 30, 2020 8:47 am
Company: Quanta

Rule 22.1: object declaration and deleted timing

Post by andy_su » Mon May 04, 2020 2:10 am

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: Select all

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

ABC::~aa() 
{ 
    delete pImpl; 
    pImpl = NULL;
}

misra-c
Posts: 569
Joined: Thu Jan 05, 2006 1:11 pm

Re: Rule 22.1: object declaration and deleted timing

Post by misra-c » Mon Jun 01, 2020 2:09 pm

The above code is a violation of rule 1.1.
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.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.22 Resources”