Why is this an issue?
This is a draft version of a MISRA C++ 202x rule proposed for public review.
MISRA Rule 15.1.1
Analysis Type: Decidable,Single Translation Unit
If an exception object of pointer type is thrown and that pointer refers to a dynamically created object, then it may be unclear which function is
responsible for destroying it, and when. This ambiguity does not exist if the object is thrown by value.
void fn( int16_t i )
static A a1;
A * a2 = new A;
if ( i > 10 )
throw &a1; // Non-compliant – pointer type thrown
throw a2; // Non-compliant – pointer type thrown
Copyright The MISRA Consortium Limited © 2023
- S1035 targets the same defect as this rule but for a non-mission-critical context.
- M23_196: MISRA C++ 2023 Rule 15.3.2 - An exception of class type shall be caught by const reference or reference