Title
Restrictions on explicit object member functions
Status
review
Section
9.3.4.6 [dcl.fct]
Submitter
Jens Maurer

Created on 2021-12-10.00:00:00 last changed 13 months ago

Messages

Date: 2023-11-10.06:40:38

CWG 2023-11-09

Progress of this issue is blocked on issue 2554.

Date: 2023-07-14.21:38:06

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, ...

Date: 2023-06-22.21:39:53

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, ...

Date: 2022-03-24.07:14:51

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.

History
Date User Action Args
2023-11-10 06:40:38adminsetmessages: + msg7509
2023-11-10 06:40:38adminsetstatus: ready -> review
2023-07-14 21:37:18adminsetstatus: review -> ready
2023-06-22 21:39:53adminsetmessages: + msg7339
2023-06-22 21:39:53adminsetstatus: drafting -> review
2023-06-16 16:50:06adminsetstatus: ready -> drafting
2023-06-15 09:15:39adminsetstatus: open -> ready
2022-03-23 23:03:41adminsetmessages: + msg6770
2021-12-10 00:00:00admincreate