This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-12-19


2553. Restrictions on explicit object member functions

Section: 9.3.4.6  [dcl.fct]     Status: review     Submitter: Jens Maurer     Date: 2021-12-10

Subclause 9.3.4.6 [dcl.fct] paragraph 6 specifies

A member-declarator with an explicit-object-parameter-declaration shall not include a ref-qualifier or a cv-qualifier-seq and shall not be declared static or virtual.

This does not address the situation when an explicit object member function becomes implicitly virtual by overriding an implicit object member function. That should be prevented.

This also does not address class-specific allocation and deallocation functions, which are implicitly static.

Proposed resolution (approved by CWG 2023-06-15) [SUPERSEDED]:

  1. Change in 9.3.4.6 [dcl.fct] paragraph 6 as follows:

    A member-declarator with an explicit-object-parameter-declaration shall not include a ref-qualifier or a cv-qualifier-seq and shall not be declared static or virtual.
  2. Change in 9.3.4.6 [dcl.fct] paragraph 7 as follows:

    ... An implicit object member function is a non-static member function without an explicit object parameter. [ Note: An explicit object member function cannot be virtual (11.7.3 [class.virtual]). -- end note ]
  3. Add a new paragraph before 11.7.3 [class.virtual] paragraph 7 as follows:

    A virtual function shall not be an explicit object member function (9.3.4.6 [dcl.fct]).

    [ Example:

      struct B {
        virtual void g(); // #1
      };
      struct D : B {
        virtual void f(this D&);  // error: explicit object member function cannot be virtual
        void g(this D&);          // error: overrides #1; explicit object member function cannot be virtual
      };
    

    -- end example]

    The ref-qualifier, or lack thereof, ...

Proposed resolution (approved by CWG 2023-07-14):

  1. Change in 9.3.4.6 [dcl.fct] paragraph 6 as follows:

    A member-declarator with an explicit-object-parameter-declaration shall not include a ref-qualifier or a cv-qualifier-seq and shall not be declared static or virtual.
  2. Change in 9.3.4.6 [dcl.fct] paragraph 7 as follows:

    ... An implicit object member function is a non-static member function without an explicit object parameter. [ Note: An explicit object member function cannot be virtual (11.7.3 [class.virtual]). -- end note ]
  3. Change in 11.4.11 [class.free] paragraph 1 as follows:

    Any allocation function for a class T is a static member (even if not explicitly declared static); it shall not have an explicit object parameter.
  4. Change in 11.4.11 [class.free] paragraph 3 as follows:

    Any deallocation function for a class T is a static member (even if not explicitly declared static); it shall not have an explicit object parameter.
  5. Change in 11.4.11 [class.free] paragraph 4 as follows:

    [ Note: Since member allocation and deallocation functions are static they cannot be virtual. -- end note ]
  6. Add a new paragraph before 11.7.3 [class.virtual] paragraph 7 as follows:

    A virtual function shall not be an explicit object member function (9.3.4.6 [dcl.fct]).

    [ Example:

      struct B {
        virtual void g(); // #1
      };
      struct D : B {
        virtual void f(this D&);  // error: explicit object member function cannot be virtual
        void g(this D&);          // error: overrides #1; explicit object member function cannot be virtual
      };
    

    -- end example]

    The ref-qualifier, or lack thereof, ...

CWG 2023-11-09

Progress of this issue is blocked on issue 2554.