Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the restrictions regarding macros away from [library] (or add links to them) #5321

Closed
dangelog opened this issue Feb 24, 2022 · 8 comments

Comments

@dangelog
Copy link
Contributor

[macro.names] says

A translation unit shall not #define or #undef names lexically identical to keywords, to the identifiers listed in Table 4, or to the attribute-tokens described in [dcl.attr], except that the names likely and unlikely may be defined as function-like macros ([cpp.replace]).

Nothing in there "depends" on the library, this restriction is purely a language matter. It would be nice to move that clause (or restate it, link to it, etc.) into [cpp] and/or [lex].

@JohelEGP
Copy link
Contributor

1 Subclause [constraints] describes restrictions on C++ programs that use the facilities of the C++ standard library.
The following subclauses specify constraints on the program's use of namespaces, its use of various reserved names, [...]

2 If a program declares or defines a name in a context where it is reserved, other than as explicitly allowed by [library], its behavior is undefined.

This is specifying library UB.

@dangelog
Copy link
Contributor Author

Sorry, could you please elaborate? My point is: why is defining a macro that is e.g. equal to a language keyword a matter for the library, rather than for the language?

@JohelEGP
Copy link
Contributor

You can change the meaning of including a C++ standard library header.

@dangelog
Copy link
Contributor Author

But the rule is broader than that. A TU that consists entirely of

#define new old

is illegal according to that clause, isn't it? So why can't the rule be moved elsewhere?

(For clarity: I'm not saying to REMOVE that paragraph; I'm asking to move it to a language-specific part, or at leats to leave links from the language-specific parts.)

@JohelEGP
Copy link
Contributor

But the rule is broader than that. A TU that consists entirely of

#define new old

is illegal according to that clause, isn't it?

A TU is not enough. It's "C++ programs that use the facilities of the C++ standard library".

@jensmaurer
Copy link
Member

jensmaurer commented Feb 24, 2022

[constraints.overview] says:

Subclause [constraints] describes restrictions on C++ programs that use the facilities of the C++ standard library.

If you don't use the standard library, you can #define keywords to your heart's content (and live with the consequences).

@dangelog
Copy link
Contributor Author

Got it, thank you.

Just wondering: is there a formal definition of "using the standard library" somewhere?

@JohelEGP
Copy link
Contributor

I don't think so.

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

No branches or pull requests

3 participants