MISRA Discussion Forums

Full Version: Proverbially Playing the `Devil's Advocate' for Rule 15-1-2
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
class A {};
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:
Quote: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):
Quote:The macro NULL is an implementation-defined C++ null pointer constant in this International Standard
Granted, the referenced `4.10' states a null pointer constant has integer (not pointer) type. However, the macro is a null pointer constant.
Rule 17-0-2 disallows the reuse of names of standard library MACROs. Reusing NULL is therefore a violation of this rule.