Skip to content

Commit 5cb8204

Browse files
committed
[cpp.replace.general] Rephrase function-like macro invocations
using the new grammar non-terminal pp-balanced-token-seq.
1 parent 12c32b9 commit 5cb8204

File tree

1 file changed

+53
-48
lines changed

1 file changed

+53
-48
lines changed

source/preprocessor.tex

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -987,18 +987,6 @@
987987
There shall be whitespace between the identifier and the replacement list
988988
in the definition of an object-like macro.
989989

990-
\pnum
991-
If the \grammarterm{identifier-list} in the macro definition does not end with
992-
an ellipsis, the number of arguments (including those arguments consisting
993-
of no preprocessing tokens)
994-
in an invocation of a function-like macro shall
995-
equal the number of parameters in the macro definition.
996-
Otherwise, there shall be at least as many arguments in the invocation as there are
997-
parameters in the macro definition (excluding the \tcode{...}). There
998-
shall exist a
999-
\tcode{)}
1000-
preprocessing token that terminates the invocation.
1001-
1002990
\pnum
1003991
\indextext{__va_args__@\mname{VA_ARGS}}%
1004992
\indextext{__va_opt__@\mname{VA_OPT}}%
@@ -1068,6 +1056,18 @@
10681056
\end{codeblock}
10691057
\end{example}
10701058

1059+
\begin{bnf}
1060+
\nontermdef{pp-balanced-token}\br
1061+
\textnormal{any} preprocessing-token \textnormal{other than \terminal{(} or \terminal{)}}\br
1062+
\terminal{(} \opt{pp-balanced-token-seq} \terminal{)}
1063+
\end{bnf}
1064+
1065+
\begin{bnf}
1066+
\nontermdef{pp-balanced-token-seq}\br
1067+
pp-balanced-token\br
1068+
pp-balanced-token pp-balanced-token-seq
1069+
\end{bnf}
1070+
10711071
\pnum
10721072
A preprocessing directive of the form
10731073
\begin{ncsimplebnf}
@@ -1081,37 +1081,53 @@
10811081
The parameters
10821082
\indextext{parameter!macro}%
10831083
are specified by the optional list of identifiers.
1084-
Each subsequent instance of the function-like macro name followed by a
1085-
\tcode{(}
1086-
as the next preprocessing token
1087-
introduces the sequence of preprocessing tokens that is replaced
1088-
by the replacement list in the definition
1089-
(an invocation of the macro).
1090-
\indextext{invocation!macro}%
1091-
The replaced sequence of preprocessing tokens is terminated by the matching
1092-
\tcode{)}
1093-
preprocessing token, skipping intervening matched pairs of left and
1094-
right parenthesis preprocessing tokens.
1095-
Within the sequence of preprocessing tokens making up an invocation
1096-
of a function-like macro,
1097-
new-line is considered a normal whitespace character.
10981084

10991085
\pnum
1086+
\indextext{invocation!macro}%
11001087
\indextext{macro!function-like!arguments}%
1101-
The sequence of preprocessing tokens
1102-
bounded by the outside-most matching parentheses
1103-
forms the list of arguments for the function-like macro.
1104-
The individual arguments within the list
1105-
are separated by comma preprocessing tokens,
1106-
but comma preprocessing tokens between matching
1107-
inner parentheses do not separate arguments.
1108-
If there are sequences of preprocessing tokens within the list of
1109-
arguments that would otherwise act as preprocessing directives,
1088+
Each instance of a function-like macro name
1089+
followed by a \tcode{(} as the next preprocessing token
1090+
shall be a function-like macro invocation of the form:
1091+
\begin{ncsimplebnf}
1092+
identifier \terminal{(} \opt{pp-balanced-token-seq} \terminal{)}
1093+
\end{ncsimplebnf}
1094+
Within the sequence of preprocessing tokens
1095+
making up an invocation of a function-like macro,
1096+
new-line is considered a normal whitespace character.
1097+
The arguments of the macro invocation are
1098+
the sequences of \grammarterm{pp-balanced-token}s
1099+
separated by comma preprocessing tokens.
1100+
If the \grammarterm{identifier-list} in the macro definition
1101+
does not end with an ellipsis,
1102+
the number of arguments
1103+
(including those arguments consisting of no \grammarterm{pp-balanced-token}s)
1104+
shall equal the number of parameters in the macro definition.
1105+
Otherwise, there shall be at least as many arguments in the invocation
1106+
as there are parameters in the macro definition (excluding the \tcode{...}).
1107+
If there are sequences of preprocessing tokens within the list of arguments
1108+
that would otherwise act as preprocessing directives,
11101109
\begin{footnote}
1111-
A \grammarterm{conditionally-supported-directive} is a preprocessing directive regardless of whether the implementation supports it.
1110+
A \grammarterm{conditionally-supported-directive} is a preprocessing directive
1111+
regardless of whether the implementation supports it.
11121112
\end{footnote}
11131113
the behavior is undefined.
11141114

1115+
\pnum
1116+
\indextext{macro!function-like!arguments}%
1117+
If there is a \tcode{...} immediately preceding the \tcode{)} in the
1118+
function-like macro
1119+
definition, then the trailing arguments (if any), including any separating comma preprocessing
1120+
tokens, are merged to form a single item: the \defn{variable arguments}. The number of
1121+
arguments so combined is such that, following merger, the number of arguments is
1122+
either equal to or
1123+
one more than the number of parameters in the macro definition (excluding the
1124+
\tcode{...}).
1125+
1126+
\pnum
1127+
Each function-like macro invocation
1128+
is replaced by the replacement list in the macro definition,
1129+
after performing argument substitution as described in \ref{cpp.subst}.
1130+
11151131
\pnum
11161132
\begin{example}
11171133
The following defines a function-like
@@ -1133,25 +1149,14 @@
11331149
the resulting expression are bound properly.
11341150
\end{example}
11351151

1136-
\pnum
1137-
\indextext{macro!function-like!arguments}%
1138-
If there is a \tcode{...} immediately preceding the \tcode{)} in the
1139-
function-like macro
1140-
definition, then the trailing arguments (if any), including any separating comma preprocessing
1141-
tokens, are merged to form a single item: the \defn{variable arguments}. The number of
1142-
arguments so combined is such that, following merger, the number of arguments is
1143-
either equal to or
1144-
one more than the number of parameters in the macro definition (excluding the
1145-
\tcode{...}).
1146-
11471152
\rSec2[cpp.subst]{Argument substitution}%
11481153
\indextext{macro!argument substitution}%
11491154
\indextext{argument substitution|see{macro, argument substitution}}%
11501155

11511156
\indextext{__va_opt__@\mname{VA_OPT}}%
11521157
\begin{bnf}
11531158
\nontermdef{va-opt-replacement}\br
1154-
\terminal{\mname{VA_OPT} (} \opt{pp-tokens} \terminal{)}
1159+
\terminal{\mname{VA_OPT} (} \opt{pp-balanced-token-seq} \terminal{)}
11551160
\end{bnf}
11561161

11571162
\pnum

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy