defined operator written in a non-standard form
ID |
objectivec.maintainability.defined_operator_nonstandard |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Preprocessor |
Language |
Objective-C |
Description
Reports a defined in the controlling expression of an #if or #elif whose operand is not a plain identifier. The two standard forms, defined IDENTIFIER and defined ( IDENTIFIER ), are not reported. This rule looks only at how the operator itself is written; defined placed where it does not belong is reported by defined-operator-misuse.
Rationale
Only those two forms are defined by the standard; anything else - an empty operand, a literal, a parenthesized expression, a nested macro invocation - is undefined behavior. The practical hazard is that most toolchains accept some of these silently and quietly evaluate the whole controlling expression as false, so the guarded code is dropped from the build without any diagnostic and the omission surfaces much later as a missing symbol.
The following code illustrates the pattern detected by this rule:
// FLAGGED: defined operator written in a non-standard form
#if defined()