- Title
- Referring to parameters in unevaluated operands of default arguments
- Status
- cd4
- Section
- 9.3.4.7 [dcl.fct.default]
- Submitter
- Faisal Vali
Created on 2015-02-09.00:00:00 last changed 116 months ago
Messages
Date: 2015-10-15.00:00:00
Proposed resolution (October, 2015): Change 9.3.4.7 [dcl.fct.default] paragraph 7 as follows:
—end example] Change 9.3.4.7 [dcl.fct.default] paragraph 8 as follows:
[Note: The
keyword this —end example] —end note]
Change 9.3.4.7 [dcl.fct.default] paragraph 9 as follows: A default argument is evaluated each time the function is
called with no argument for the corresponding
parameter. —end example]
Local variables A local variable
shall not be used appear as a
potentially-evaluated expression in a default
argument. [Example:
void f() {
int i;
extern void g(int x = i); // error
extern void h(int x = sizeof(i)); // OK
// ...
}
shall may
not be used appear in a default
argument of a member function; see
_N4567_.5.1.1 [expr.prim.general]. [Example:
class A {
void f(A* p = this) { } // error
};
The order of evaluation of function
arguments is unspecified. Consequently, parameters of a
function shall not be used in a default argument, even if
they are not evaluated. A parameter shall not
appear as a potentially-evaluated expression in a default
argument. Parameters of a function declared before a
default argument are in scope and can hide namespace and
class member names. [Example:
int a;
int f(int a, int b = a); // error: parameter a
// used as default argument
typedef int I;
int g(float I, int b = I(2)); // error: parameter I found
int h(int a, int b = sizeof(a)); //
error, parameter a used OK, unevaluated operand
// in default argument
Similarly,
a A non-static member shall not be
used appear in a default argument,
even if it is not evaluated, unless it appears as
the id-expression of a class member access expression
(7.6.1.5 [expr.ref]) or unless it is used to form a
pointer to member
(7.6.2.2 [expr.unary.op]). [Example:...
Date: 2016-02-15.00:00:00
[Adopted at the February, 2016 meeting.] According to 9.3.4.7 [dcl.fct.default] paragraph 9, This prohibits use of parameters in unevaluated operands, e.g., This wording predates the concept of “unevaluated
operands” (the phrase “not evaluated” refers
to calls to the function where an actual argument is supplied and
thus the default argument is not used, not to unevaluated
operands) and should not apply to such cases.
A default argument is evaluated each time the function is
called with no argument for the corresponding parameter. The
order of evaluation of function arguments is
unspecified. Consequently, parameters of a function shall
not be used in a default argument, even if they are not
evaluated.
void foo(int a = decltype(a){});
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2017-02-06 00:00:00 | admin | set | status: ready -> cd4 |
| 2015-11-10 00:00:00 | admin | set | messages: + msg5579 |
| 2015-11-10 00:00:00 | admin | set | status: drafting -> ready |
| 2015-02-09 00:00:00 | admin | create | |