Skip to content

Commit 89c81c0

Browse files
jensmaurerzygoloid
authored andcommitted
CWG2233 Function parameter packs following default arguments
1 parent 985fe9d commit 89c81c0

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

source/declarators.tex

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,10 @@
16441644
\grammarterm{parameter-declaration}{} this
16451645
\grammarterm{initializer-clause}{}
16461646
is used as a default argument.
1647-
Default arguments will be used in calls where trailing arguments are missing.
1647+
\begin{note}
1648+
Default arguments will be used in calls
1649+
where trailing arguments are missing\iref{expr.call}.
1650+
\end{note}
16481651

16491652
\pnum
16501653
\indextext{argument!example of default}%
@@ -1709,7 +1712,8 @@
17091712
In
17101713
a given function declaration, each parameter subsequent to a
17111714
parameter with a default argument shall have a default argument
1712-
supplied in this or a previous declaration
1715+
supplied in this or a previous declaration,
1716+
unless the parameter was expanded from a parameter pack,
17131717
or shall be a function parameter pack.
17141718
A default argument
17151719
shall not be redefined by a later declaration (not even to the
@@ -1735,6 +1739,10 @@
17351739
void n() {
17361740
f(6); // OK, calls \tcode{f(6, 7)}
17371741
}
1742+
template<class ... T> struct C {
1743+
void f(int n = 0, T...);
1744+
};
1745+
C<int> c; // OK, instantiates declaration \tcode{void C::f(int n = 0, int)}
17381746
\end{codeblock}
17391747
\end{example}
17401748
For a given inline function defined in different translation units,

source/expressions.tex

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,12 +2237,21 @@
22372237
\indextext{function argument|see{argument}}%
22382238
\indextext{function parameter|see{parameter}}%
22392239
\indextext{initialization!parameter}%
2240-
When a function is called, each parameter\iref{dcl.fct} shall be
2240+
When a function is called, each parameter\iref{dcl.fct} is
22412241
initialized~(\ref{dcl.init}, \ref{class.copy}, \ref{class.ctor}) with
22422242
its corresponding argument.
2243+
If there is no corresponding argument,
2244+
the default argument for the parameter is used;
2245+
the program is ill-formed if one is not present.
2246+
\begin{example}
2247+
\begin{codeblock}
2248+
template<typename ...T> int f(int n = 0, T ...t);
2249+
int x = f<int>(); // error: no argument for second function parameter
2250+
\end{codeblock}
2251+
\end{example}
22432252
If the function is a non-static member
22442253
function, the \tcode{this} parameter of the function\iref{class.this}
2245-
shall be initialized with a pointer to the object of the call, converted
2254+
is initialized with a pointer to the object of the call, converted
22462255
as if by an explicit type conversion\iref{expr.cast}.
22472256
\begin{note}
22482257
There is no access or ambiguity checking on this conversion; the access

0 commit comments

Comments
 (0)