<html>
<head>
<title>Wording for brace-initializers as default arguments</title>

<style type="text/css">
  ins { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  del { text-decoration:line-through; background-color:#FFA0A0 }
</style>
</head>

<body>
Jens Maurer<br/>
2010-11-12<br/>
N3217=10-0207

<h1>Wording for brace-initializers as default arguments</h1>

This paper presents detailed wording changes relative to the current
C++ Working Draft N3126 to implement brace-initializers for default
arguments for functions, as proposed in N3139 "An Incomplete Language
Feature" by Bjarne Stroustrup, thereby also addressing core issue 994.
<p>

Change the grammar in 8.3.5 dcl.fct paragraph 3:
<blockquote>
<pre><em>
parameter-declaration:
      attribute-specifier<sub>opt</sub> decl-specifier-seq declarator
      attribute-specifier<sub>opt</sub> decl-specifier-seq declarator = <ins>initializer-clause</ins> <del>assignment-expression</del>
      attribute-specifier<sub>opt</sub> decl-specifier-seq abstract-declarator<sub>opt</sub>
      attribute-specifier<sub>opt</sub> decl-specifier-seq abstract-declarator<sub>opt</sub> = <ins>initializer-clause</ins> <del>assignment-expression</del></em>
</blockquote>

Change in 8.3.6 dcl.fct.default paragraph 1:
<blockquote>
If an <del>expression</del> <ins><em>initializer-clause</em></ins> is
specified in a <del>parameter declaration</del>
<ins><em>parameter-declaration</em></ins> this
<del>expression</del> <ins><em>initializer-clause</em></ins> is used
as a default argument. Default arguments will be used in calls where
trailing arguments are missing.
</blockquote>

Change in 8.3.6 dcl.fct.default paragraph 3:
<blockquote>
A default argument <del>expression</del> shall be specified only in
the <em>parameter-declaration-clause</em> of a function declaration or
in a <em>template-parameter</em> (14.1 temp.param)<ins>; in the latter
case, the <em>initializer-clause</em> shall be an
<em>assignment-expression</em></ins>. <del>It</del> <ins>A default
argument</ins> shall not be specified for a parameter pack. ...
</blockquote>

Change in 8.3.6 dcl.fct.default paragraph 5:
<blockquote>
A default argument <del>expression</del> is implicitly converted
(Clause 4 conv) to the parameter type. The default argument
<del>expression</del> has the same semantic constraints as the
initializer <del>expression</del> in a declaration of a variable of
the parameter type, using the copy-initialization semantics (8.5
dcl.init). The names in the <ins>default argument</ins>
<del>expression</del> are bound, and the semantic constraints are
checked, at the point where the
default argument <del>expression</del> appears.
Name lookup and checking of semantic constraints for default arguments
in function templates and in member functions of class templates are
performed as described in 14.7.1 temp.inst. [ Example: ... ] [ Note:
in member function declarations, names in default <ins>arguments</ins>
<del>argument expressions</del> are looked up as described in 3.4.1
basic.lookup.unqual. Access checking applies to names in default
<ins>arguments</ins> <del>argument expressions</del> as described in
Clause 11 class.access. -- end note ]
</blockquote>

Change in 8.3.6 dcl.fct.default paragraph 7:
<blockquote>
Local variables shall not be used in <ins>a</ins> default
argument<del> expressions</del>. [ Example: ... ]
</blockquote>

Change in 8.3.6 dcl.fct.default paragraph 9:
<blockquote>
... Consequently, parameters of a function shall not be used in <ins>a</ins>
default argument<del> expressions</del>, even if they are not
evaluated.  Parameters of a function declared before a default argument
<del>expression</del> are in scope and can hide namespace and class
member names. [ Example: ... ] 
Similarly, a non-static member shall not be used in a default
argument<del>expression</del>, even if it is not evaluated, unless it
appears as the <em>id-expression</em> of a class member access
expression (5.2.5 expr.ref) or unless it is used to form a pointer to
member (5.3.1 expr.unary.op). [ Example: ... ]
</blockquote>

Change 1.9 intro.execution paragraph 11:
<blockquote>
[ Note: the evaluation of a full-expression can include the evaluation
of subexpressions that are not lexically
part of the full-expression.  For example, subexpressions involved in
evaluating default <ins>arguments</ins> <del>argument
expressions</del> (8.3.6 dcl.fct.default) are considered to be created
in the expression that calls the function, not the expression that
defines the default argument. -- end note ]
</blockquote>

Change in 3.4.1 basic.lookup.unqual paragraph 6:
<blockquote>
A name used in the definition of a function following the function's
<em>declarator-id</em> [ Footnote:  This refers to unqualified names
that occur, for instance, in a type or default argument
<del>expression</del> in the <em>parameter-declaration-clause</em> or
used in the function body. ] that is a member of namespace N (where,
only for the purpose of exposition, N could represent the global
scope) shall be declared before its use in the block in which it is
used or in one of its enclosing blocks (6.3 stmt.block) or, shall be declared
before its use in namespace N or, if N is a nested namespace, shall be
declared before its use in one of N's enclosing namespaces. [ Example:
... ]
</blockquote>

Change in 3.4.1 basic.lookup.unqual paragraph 8:
<blockquote>
A name used in the definition of a member function (9.3 class.mfct) of
class X following the function's declarator-id [ Footnote: That is, an
unqualified name that occurs, for instance, in a type or default
argument <del>expression</del> in the
<em>parameter-declaration-clause</em> or in the function body. ]
or in the <em>brace-or-equal-initializer</em> of a non-static data
member (9.2 class.mem) of class X shall be declared in one of the
following ways:
...
</blockquote>

Change in 7.1.2 dcl.fct.spec paragraph 4:
<blockquote>
... [ Note: A string literal appearing in a default argument
<del>expression</del> is not in the body of an inline function merely
because the expression is used in a function call from that inline
function. -- end note ] ...
</blockquote>

Change in 8.5 dcl.init paragraph 3:
<blockquote>
[ Note: default <ins>arguments</ins> <del>argument expressions</del>
are more restricted; see 8.3.6 dcl.fct.default.
</blockquote>

Change in 11 class.access paragraph 8:
<blockquote>
The names in a default argument <del>expression</del> (8.3.6
dcl.fct.default) are bound at the point of declaration, and access is
checked at that point rather than at any points of use of the default
argument <del>expression</del>. ...
</blockquote>

Change in 12.2 class.temporary paragraph 4:
<blockquote>
If the constructor has one or more default arguments, the destruction
of every temporary created in a default argument <del>expression</del>
is sequenced before the construction of the next array element, if
any.
</blockquote>

<p>

Change in 14.7.1 temp.inst paragraph 11:
<blockquote>
If a function template <code>f</code> is called in a way that requires
a default argument <del>expression</del> to be used, the dependent
names are looked up, the semantics constraints are checked, and the
instantiation of any template
used in the default argument <del>expression</del> is done as if the
default argument <del>expression</del> had been an
<del>expression</del> <ins>initializer</ins>
used in a function template specialization with the same scope, the
same template parameters and the same
access as that of the function template <code>f</code> used at that
point. ...
</blockquote>


</body>
</html>
