cplusplus / CWG

Core Working Group
23 stars 7 forks source link

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

Closed sdkrystian closed 5 months ago

sdkrystian commented 8 months ago

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-declarator~non-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.

jensmaurer commented 8 months ago

CWG2846

sdkrystian commented 8 months ago

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

sdkrystian commented 8 months ago

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?

jensmaurer commented 8 months ago

I've generalized the wording.