Skip to content

CWG2846 [dcl.fct] Out-of-line definitions of explicit object member functions #493

Description

@sdkrystian

Full name of submitter: Krystian Stasiowski

Reference (section label): [dcl.fct]

Link to reflector thread (if any): N/A

Issue description:

According to [dcl.fct] p6:

An explicit-object-parameter-declaration is a parameter-declaration with a this specifier. An explicit-object-parameter-declaration shall appear only as the first parameter-declaration of a parameter-declaration-list of either:

  • a member-declarator that declares a member function, or
  • a lambda-declarator.

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.

In the following example:

struct A
{
    void f(this A&);
};

void A::f(this A&) { }

The out-of-line definition of A::f is not a member-declarator, therefore it cannot contain an explicit-object-parameter-declaration. However, this is accepted by clang, GCC, EDG, and MSVC.

Suggested resolution:

Replace the first subbullet of [dcl.fct] p6 with:

  • a declaration of a non-static member function, or

Change the final sentence of [dcl.fct] p6 as follows (note: this affects some of the wording touched by CWG2553:

A member-declaratornon-static member function 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.

Activity

  1. jensmaurer commented on Jan 29, 2024

    @jensmaurer
    Member
  2. changed the title [-][dcl.fct] Out-of-line definitions of explicit object member functions[/-] [+]CWG2846 [dcl.fct] Out-of-line definitions of explicit object member functions[/+] on Jan 29, 2024
  3. sdkrystian commented on Jan 30, 2024

    @sdkrystian
    Author

    @jensmaurer I'm not sure the proposed wording in the issue is quite correct. Consider the following:

    struct A 
    {
        template<typename T> 
        void f(this T);
    };
    template<>
    void A::f(this int);

    The explicit specialization of A::f is neither a member-declarator nor a function-definition.

  4. sdkrystian commented on Jan 30, 2024

    @sdkrystian
    Author

    Now that I think about it, the declaration of a template-declaration or explicit-specialization is never a member-declaration... should I open another issue for this?

  5. jensmaurer commented on Jan 30, 2024

    @jensmaurer
    Member

    I've generalized the wording.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions