Proverbially Playing the `Devil's Advocate' for Rule 15-1-2

Moderators: david ward, misra cpp

Post Reply
gs
Posts: 87
Joined: Thu Nov 18, 2004 1:39 am

Proverbially Playing the `Devil's Advocate' for Rule 15-1-2

Post by gs » Thu Sep 11, 2008 7:46 pm

The text and rationale of rule 15-1-2 make no mention of the word `macro'. Let us suppose an application made no reference to the Standard Library within it's source code. Consequently, the `NULL' macro has not been defined. Would the following code violate rule 15-1-2?

Code: Select all

class A {};
A NULL;
void f()
    {
    throw NULL;
    }
The very premise of the rationale for the rule is invalid. In this case a `throw NULL;' is not equivalent to `throw (0);' and is not a throwing of an integer expression.

Furthermore, the wording of the rationale is slightly incorrect:
throw(NULL) (equivalent to throw(0)) is never a throw of the null-pointer-constant ...
To quote ISO C++, 18.1, para. 4, (lib.support.types):
The macro NULL is an implementation-defined C++ null pointer constant in this International Standard
(4.10).
Granted, the referenced `4.10' states a null pointer constant has integer (not pointer) type. However, the macro is a null pointer constant.

misra cpp
Posts: 150
Joined: Mon Jun 02, 2008 1:55 pm
Company: MISRA

Re: Proverbially Playing the `Devil's Advocate' for Rule 15-1-2

Post by misra cpp » Wed Oct 07, 2015 9:55 am

Rule 17-0-2 disallows the reuse of names of standard library MACROs. Reusing NULL is therefore a violation of this rule.
Posted by and on behalf of
the MISRA C++ Working Group

Post Reply

Return to “6.15 Exception handling (C++)”