Skip to content

Conversation

@AlisdairM
Copy link
Contributor

@AlisdairM AlisdairM commented Nov 14, 2025

Move seemingly normative reference to keywords in #if expressions into a note.

Comment on lines 564 to +567
\begin{note}
Keywords are identifiers during preprocessing and are not valid macro names,
so are always replaced by \tcode{0} before being converted into a token.
\end{note}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this note after we've removed "keyword" in the first place?

We do mention "true" and "false" as identifiers above, so there is a strong hint that phase 7 keywords are in view here.
If keywords were a separate thing, the note below would need to be amended with "keywords", too, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We mention true as, being an identifier that is not defined as a macro, it should convert to a 0 before we turn the preprocessor tokens into tokens in order to evaluate the #if predicate --- we arrange that the only tokens that convert are literals. I think the first note covers that, and the alternative tokens note covers a different matter as alternative tokens are never identifiers. Maybe I am too focused on identifiers as a preprocessing-token that is being converted though?

Copy link
Member

@jensmaurer jensmaurer Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to say that your new "note" can go entirely, because "true" is a keyword and is mentioned in the (revised) "identifiers except..." phrasing. That wouldn't be necessary if "true" weren't considered a (preprocessor-level) identifier at that point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy to remove the note --- should I do so now, or wait for more feedback in case others prefer to add the note? I agree that my preference would be to remove the note as I doubt folks would be genuinely confused.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For comparison, C23 says

... all remaining identifiers other than true (including those lexically identical to keywords such as false) are replaced with the pp-number 0, true is replaced with pp-number 1, and then each preprocessing token is converted into a token.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, true and false are essentially integer literals in C, but are boolean literals in C++. By preserving the spelling of the token, we preserve the type in the expression. I do not know how significant that change might be, but if we were to synchronize wording with C it would definitely become a CWG issue due to that type change.

Copy link
Member

@jensmaurer jensmaurer Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering how you would observe the type change at the preprocessor #if level.

That said, the more important part for this pull request is the parenthetical "(including those lexically identical to keywords)" which re-emphasizes that phase 4 "identifiers" can be spelled like phase 7 keywords. That's another option, instead of the note.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the note is kept, please leave it at "Keywords are identifiers during preprocessing and are not valid macro names."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants