|
622 | 622 | an ellipsis, the number of arguments (including those arguments consisting
|
623 | 623 | of no preprocessing tokens)
|
624 | 624 | 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 |
626 | 627 | parameters in the macro definition (excluding the \tcode{...}). There
|
627 | 628 | shall exist a
|
628 | 629 | \tcode{)}
|
629 | 630 | preprocessing token that terminates the invocation.
|
630 | 631 |
|
631 | 632 | \pnum
|
632 | 633 | \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} |
634 | 637 | of a function-like macro that uses the ellipsis notation in the parameters.
|
635 | 638 |
|
636 | 639 | \pnum
|
|
731 | 734 | \indextext{macro!function-like!arguments}%
|
732 | 735 | If there is a \tcode{...} immediately preceding the \tcode{)} in the
|
733 | 736 | 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 |
735 | 738 | tokens, are merged to form a single item: the \term{variable arguments}. The number of
|
736 | 739 | arguments so combined is such that, following merger, the number of arguments is
|
| 740 | +either equal to or |
737 | 741 | one more than the number of parameters in the macro definition (excluding the
|
738 | 742 | \tcode{...}).
|
739 | 743 |
|
|
760 | 764 | no other preprocessing tokens are available.
|
761 | 765 |
|
762 | 766 | \pnum
|
| 767 | +\indextext{__VA_ARGS__@\mname{VA_ARGS}}% |
763 | 768 | An identifier \mname{VA_ARGS} that occurs in the replacement list
|
764 | 769 | shall be treated as if it were a parameter, and the variable arguments shall form
|
765 | 770 | the preprocessing tokens used to replace it.
|
766 | 771 |
|
| 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 | + |
767 | 821 | \rSec2[cpp.stringize]{The \tcode{\#} operator}%
|
768 | 822 | \indextext{\#\#0 operator@\tcode{\#} operator}%
|
769 | 823 | \indextext{stringize|see{\tcode{\#} operator}}
|
|
0 commit comments