Title
Use of default arguments depending on shape of postfix-expression in a function call
Status
open
Section
7.6.1.3 [expr.call]
Submitter
Benjamin Sch.

Created on 2025-08-09.00:00:00 last changed 3 weeks ago

Messages

Date: 2025-08-09.00:00:00

(From submission #744.)

Consider:

  void f(int = 0) {}

  void g() {
    f();          // accepted by all
    (&f)();       // accepted by EDG and clang, rejected by GCC and MSVC
    (*f)();       // accepted by EDG and MSVC, rejected by GCC and clang 
    (0, f)();     // accepted by EDG, rejected by MSVC, GCC and clang
    static_cast<void(&)(int)>(f)();  // accepted by MSVC, rejected by EDG, GCC, and clang
    static_cast<void(*)(int)>(f)();  // rejected by all

    auto p = f;
    p();          // rejected by all
  }

It seems reasonably clear from 12.2.2.2.1 [over.match.call.general] that only the first two cases involve overload resolution for a function call; the rest does not. Default arguments are only considered when overload resolution for a function call selected the function; 7.6.1.3 [expr.call] paragraph 6 should be clarified.

Possible resolution:

See also core issue 2989.

  1. Change in 7.6.1.3 [expr.call] paragraph 6 as follows:

    When a function is called, each parameter (9.3.4.6 [dcl.fct]) is initialized (9.5 [dcl.init], 11.4.5.3 [class.copy.ctor]) with its corresponding argument, and each precondition assertion of the function is evaluated (9.4.1 [dcl.contract.func]). If the function is an explicit object member function and there is an implied object argument (12.2.2.2.2 [over.call.func]), the list of provided arguments is preceded by the implied object argument for the purposes of this correspondence. If the function to be called is selected by overload resolution (12.2.2.2.1 [over.match.call.general]) and there is no corresponding argument, the default argument for the parameter is used. ...
  2. Change in 12.2.2.2.1 [over.match.call.general] paragraph 2 as follows:

    If the postfix-expression is of the (possibly parenthesized) form & primary-expression, where the primary-expression is a possibly-parenthesized id-expression or splice-expression and is the address of an overload set, overload resolution is applied using that set as described above. ...
History
Date User Action Args
2025-08-09 00:00:00admincreate