Title
Casts in preprocessor conditional expressions
Status
cd2
Section
15.2 [cpp.cond]
Submitter
Martin Sebor

Created on 2007-02-12.00:00:00 last changed 179 months ago

Messages

Date: 2009-10-15.00:00:00

[Voted into WP at October, 2009 meeting.]

Date: 2009-07-15.00:00:00

Proposed resolution (July, 2009):

Change 15.2 [cpp.cond] paragraph 1 as follows:

The expression that controls conditional inclusion shall be an integral constant expression except that: it shall not contain a cast; identifiers (including those lexically identical to keywords)...
Date: 2007-04-15.00:00:00

Notes from the April, 2007 meeting:

The CWG agreed with this suggested resolution; however, the reference is in the “Preprocessing Directives” clause, which WG21 intends to keep in as close synchronization as possible with the corresponding wording in the C Standard. Any change here must therefore be done in consultation with WG14. Clark Nelson will fulfill this liaison function.

It was also noted that the imminent introduction of constexpr also has the potential for a similar kind of confusion, so the proposed resolution should address both casts and constexpr.

Date: 2007-02-12.00:00:00

15.2 [cpp.cond] 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 and misleading: 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 wording on casts should be removed and replaced by a note recognizing this implication.

History
Date User Action Args
2010-03-29 00:00:00adminsetstatus: dr -> cd2
2009-11-08 00:00:00adminsetmessages: + msg2480
2009-11-08 00:00:00adminsetstatus: ready -> dr
2009-08-03 00:00:00adminsetmessages: + msg2180
2009-08-03 00:00:00adminsetstatus: drafting -> ready
2007-05-06 00:00:00adminsetmessages: + msg1491
2007-05-06 00:00:00adminsetstatus: open -> drafting
2007-02-12 00:00:00admincreate