For non-template functions, default arguments can be added in later
declarations of a
function that inhabit the same scope
. Declarations that inhabit different
scopes have completely distinct sets of default arguments
. That
is, declarations in inner scopes do not acquire default
arguments from declarations in outer scopes, and vice versa
. In
a given function declaration, each parameter subsequent to a
parameter with a default argument shall have a default argument
supplied in this or a previous declaration,
unless the parameter was expanded from a parameter pack,
or shall be a function parameter pack
. [
Note 2:
A default argument
cannot be redefined by a later declaration
(not even to the same value) (
[basic.def.odr])
. —
end note]
[
Example 2:
void g(int = 0, ...);
void f(int, int);
void f(int, int = 7);
void h() {
f(3);
void f(int = 1, int);
}
void m() {
void f(int, int);
f(4);
void f(int, int = 5);
f(4);
void f(int, int = 5);
}
void n() {
f(6);
}
template<class ... T> struct C {
void f(int n = 0, T...);
};
C<int> c;
—
end example]
For a given inline function defined in different translation units,
the accumulated sets of default arguments at the end of the
translation units shall be the same; no diagnostic is required
. If a friend declaration
D specifies a default argument expression,
that declaration shall be a definition and there shall be no other
declaration of the function or function template
which is reachable from
D or from which
D is reachable
.