Created on 2015-02-09.00:00:00 last changed 94 months ago
Proposed resolution (October, 2015):
Change 9.3.4.7 [dcl.fct.default] paragraph 7 as follows:
Local variablesA local variable shall notbe usedappear 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 // ... }—end example]
Change 9.3.4.7 [dcl.fct.default] paragraph 8 as follows:
[Note: The keyword this
shallmay notbe usedappear 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 };
—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.
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, parameterausedOK, unevaluated operand// in default argument—end example]
Similarly, aA non-static member shall notbe usedappear 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:...
[Adopted at the February, 2016 meeting.]
According to 9.3.4.7 [dcl.fct.default] paragraph 9,
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.
This prohibits use of parameters in unevaluated operands, e.g.,
void foo(int a = decltype(a){});
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.
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 |