According to N3092 (final committee draft of C++11), in 16.3: Macro replacement, object-like macro is defined as:
# define identifier replacement-list new-line
and function-like macro is defined as:
# define identifier lparen identifier-list_opt ) replacement-list new-line # define identifier lparen ... ) replacement-list new-line # define identifier lparen identifier-list , ... ) replacement-list new-line
All have replacement-list (so-called macro value) and this is defined as:
replacement-list: pp-tokensopt
and pp-tokens is defined as:
pp-tokens: preprocessing-token pp-tokens preprocessing-token
and preprocessing-token is, for example, identifier.
As far as I read these, a macro with an empty value is well-defined.
However, 16.3-3 says:
There shall be white-space between the identifier and the replacement list in the definition of an object-like macro.
and note that replacement-list itself is not optional (though it can have an empty value).
So I believe:
//well-formed (function-like macro with value)
#define f(x) (x)<NEWLINE>
//well-formed (function-like macro without value)
#define f(x)<NEWLINE>
//well-formed (function-like macro without value)
#define f(x) <NEWLINE>
//well-formed (object-like macro with value)
#define f hello<NEWLINE>
//**ill-formed** (object-like macro without value)
#define f<NEWLINE>
//well-formed (object-like macro without value)
#define f <NEWLINE>
and thus, for example, a so-called "include guard" should be of the form:
#ifndef is_xyz_included<NEWLINE>
#define is_xyz_included <NEWLINE> // NOTE THE SPACE BEFORE <NEWLINE>
#endif<NEWLINE>
Is my interpretation wrong?
#define FOO
should be valid), then it doesn't directly matter either to implementers or to users. But it's worth pointing out and fixing. – Keith Thompson May 23 '19 at 22:07