Submitter: Clark Nelson
Submission Date: 2007-04-23
Source: WG21
Reference Document: N/A
Version: 1.2
Date: 2007-07-21
Subject: Casts in preprocessor conditional expressions
Summary
6.10.1 paragraph 1 states:
The expression that controls conditional inclusion shall be an integral constant expression except that: it shall not contain a cast; ...
The prohibition of casts is vacuous, as pointed out in the footnote in that paragraph:
Because the controlling constant expression is evaluated during translation phase 4, all identifiers either are or are not macro names — there simply are no keywords, enumeration constants, and so on.
As a result, there can be no casts, which require either keywords or identifiers that resolve to types in order to be recognized as casts.
The prohibition of casts is also misleading: the presence of a "shall not" in a "Constraints" paragraph suggests that an implementation is required to diagnose this condition. However, in an example like this:
#if (int)+0
There is a construct which appears to be a cast, but is not, and is syntactically and semantically valid.
Suggested Technical Corrigendum
Change 6.10.1p1:
The expression that controls conditional inclusion shall be an integer constant expression except that:it shall not contain a cast;identifiers (including those lexically identical to keywords) are interpreted as described below;141) and it may contain unary operator expressions of the form
Technical Corrigendum
Change 6.10.1p1:
The expression that controls conditional inclusion shall be an integer constant expression except that:it shall not contain a cast;identifiers (including those lexically identical to keywords) are interpreted as described below;141) and it may contain unary operator expressions of the form