Skip to content

Commit 6e5722c

Browse files
committed
P0306R4 Comma omission and comma deletion
[cpp.subst] Replace "is" with "would be" when talking about a hypothetical alternative replacement list.
1 parent 187bab3 commit 6e5722c

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

source/preprocessor.tex

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,15 +622,18 @@
622622
an ellipsis, the number of arguments (including those arguments consisting
623623
of no preprocessing tokens)
624624
in an invocation of a function-like macro shall
625-
equal the number of parameters in the macro definition. Otherwise, there shall be more arguments in the invocation than there are
625+
equal the number of parameters in the macro definition.
626+
Otherwise, there shall be at least as many arguments in the invocation as there are
626627
parameters in the macro definition (excluding the \tcode{...}). There
627628
shall exist a
628629
\tcode{)}
629630
preprocessing token that terminates the invocation.
630631

631632
\pnum
632633
\indextext{__VA_ARGS__@\mname{VA_ARGS}}%
633-
The identifier \mname{VA_ARGS} shall occur only in the \grammarterm{replacement-list}
634+
\indextext{__VA_OPT__@\mname{VA_OPT}}%
635+
The identifiers \mname{VA_ARGS} and \mname{VA_OPT}
636+
shall occur only in the \grammarterm{replacement-list}
634637
of a function-like macro that uses the ellipsis notation in the parameters.
635638

636639
\pnum
@@ -731,9 +734,10 @@
731734
\indextext{macro!function-like!arguments}%
732735
If there is a \tcode{...} immediately preceding the \tcode{)} in the
733736
function-like macro
734-
definition, then the trailing arguments, including any separating comma preprocessing
737+
definition, then the trailing arguments (if any), including any separating comma preprocessing
735738
tokens, are merged to form a single item: the \term{variable arguments}. The number of
736739
arguments so combined is such that, following merger, the number of arguments is
740+
either equal to or
737741
one more than the number of parameters in the macro definition (excluding the
738742
\tcode{...}).
739743

@@ -760,10 +764,60 @@
760764
no other preprocessing tokens are available.
761765

762766
\pnum
767+
\indextext{__VA_ARGS__@\mname{VA_ARGS}}%
763768
An identifier \mname{VA_ARGS} that occurs in the replacement list
764769
shall be treated as if it were a parameter, and the variable arguments shall form
765770
the preprocessing tokens used to replace it.
766771

772+
\pnum
773+
\indextext{__VA_OPT__@\mname{VA_OPT}}%
774+
The identifier \mname{VA_OPT}
775+
shall always occur as part of the token sequence
776+
\mname{VA_OPT}\tcode{(}\placeholder{content}\tcode{)},
777+
where \placeholder{content} is
778+
an arbitrary sequence of \grammarterm{preprocessing-tokens}
779+
other than \mname{VA_OPT},
780+
which is terminated by the closing \tcode{)}
781+
and skips intervening pairs of matching left and right parentheses.
782+
If \placeholder{content} would be ill-formed
783+
as the replacement list of the current function-like macro,
784+
the program is ill-formed.
785+
The token sequence
786+
\mname{VA_OPT}\tcode{(}\placeholder{content}\tcode{)}
787+
shall be treated as if it were a parameter,
788+
and the preprocessing tokens used to replace it
789+
are defined as follows.
790+
If the variable arguments consist of no tokens,
791+
the replacement consists of
792+
a single placemarker preprocessing token~(\ref{cpp.concat}, \ref{cpp.rescan}).
793+
Otherwise, the replacement consists of
794+
the results of the expansion of \placeholder{content}
795+
as the replacement list of the current function-like macro
796+
before rescanning and further replacement.
797+
\begin{example}
798+
\begin{codeblock}
799+
#define F(...) f(0 __VA_OPT__(,) __VA_ARGS__)
800+
#define G(X, ...) f(0, X __VA_OPT__(,) __VA_ARGS__)
801+
#define SDEF(sname, ...) S sname __VA_OPT__(= { __VA_ARGS__ })
802+
803+
F(a, b, c) // replaced by \tcode{f(0, a, b, c)}
804+
F() // replaced by \tcode{f(0)}
805+
806+
G(a, b, c) // replaced by \tcode{f(0, a, b, c)}
807+
G(a, ) // replaced by \tcode{f(0, a)}
808+
G(a) // replaced by \tcode{f(0, a)}
809+
810+
SDEF(foo); // replaced by \tcode{S foo;}
811+
SDEF(bar, 1, 2); // replaced by \tcode{S bar = \{ 1, 2 \};}
812+
813+
#define H1(X, ...) X __VA_OPT__(##) __VA_ARGS__ // ill-formed: \tcode{\#\#} may not appear at
814+
// the beginning of a replacement list (\ref{cpp.concat})
815+
#define H2(X, Y, ...) __VA_OPT__(X ## Y,) __VA_ARGS__
816+
817+
H2(a, b, c, d) // replaced by \tcode{ab, c, d}
818+
\end{codeblock}
819+
\end{example}
820+
767821
\rSec2[cpp.stringize]{The \tcode{\#} operator}%
768822
\indextext{\#\#0 operator@\tcode{\#} operator}%
769823
\indextext{stringize|see{\tcode{\#} operator}}

0 commit comments

Comments
 (0)