Title
Forward reference to default argument
Status
open
Section
9.3.4.7 [dcl.fct.default]
Submitter
Steve Clamage

Created on 2002-06-17.00:00:00 last changed 40 months ago

Messages

Date: 2020-11-15.00:00:00

Additional note (November, 2020):

Paper P1787R6, adopted at the November, 2020 meeting, partially addresses this issue.

Date: 2013-10-15.00:00:00

Additional note (October, 2013):

Issue 1330 treats exception-specifications like default arguments, evaluated in the completed class type. That raises the same questions regarding self-referential noexcept clauses that apply to default arguments.

Date: 2013-03-15.00:00:00

Additional note (March, 2013):

Additional discussion has occurred suggesting the following examples as illustrations of this issue:

  struct B {
    struct A { int a = 0; };
    B(A = A());    // Not permitted?
  };

as well as

  struct C {
   struct A { int a = C().n; }; // can we use the default argument here?
   C(int k = 0);
   int n;
  };

  bool f();
  struct D {
   struct A { bool a = noexcept(B()); }; // can we use the default initializer here?
   struct B { int b = f() ? throw 0 : 0; };
  };

(See also issue 325.)

Date: 2012-02-15.00:00:00

Notes from the February, 2012 meeting:

Implementations seem to have come to agreement that this example is ill-formed.

Date: 2004-09-10.00:00:00

Is this program well-formed?

  struct S {
    static int f2(int = f1()); // OK?
    static int f1(int = 2);
  };
  int main()
  {
    return S::f2();
  }

A class member function can in general refer to class members that are declared lexically later. But what about referring to default arguments of member functions that haven't yet been declared?

It seems to me that if f2 can refer to f1, it can also refer to the default argument of f1, but at least one compiler disagrees.

History
Date User Action Args
2020-12-15 00:00:00adminsetmessages: + msg6270
2013-10-14 00:00:00adminsetmessages: + msg4651
2013-10-14 00:00:00adminsetstatus: drafting -> open
2013-03-18 00:00:00adminsetmessages: + msg4257
2012-02-27 00:00:00adminsetmessages: + msg3768
2012-02-27 00:00:00adminsetstatus: open -> drafting
2002-06-17 00:00:00admincreate