Skip to content

[basic.scope.scope] Is void adjustment and cv-qualifier adjustment applied when considering corresponding overload #577

Closed
@ranaanoop

Description

@ranaanoop

Full name of submitter: Anoop Rana

Reference (section label): [basic.scope.scope]

Issue description:
Consider the following program for which we see compiler divergence but which seems to be well-formed as per current wording. Out of the 4 major compilers only gcc accept the code while all other three(clang, edg and msvc) rejects it.


struct A {
    void f(this void);
    void f();          //gcc: OK, EDG:Nope, Clang: Nope, MSVC:Nope
};

As per my understanding this is well-formed for the reason explained below.

From basic.scope.scope#3 and basic.scope.scope#4.4:

Two non-static member functions have corresponding object parameters if:

  • exactly one is an implicit object member function with no ref-qualifier and the types of their object parameters ([dcl.fct]), after removing top-level references, are the same, or
  • their object parameters have the same type.

Two function or function template declarations declare corresponding overloads if:

  • both declare functions with the same non-object-parameter-type-list,17 equivalent ([temp.over.link]) trailing requires-clauses (if any, except as specified in [temp.friend]), and, if both are non-static members, they have corresponding object parameters, or

Now let's apply this our example. First, here exactly one of the declarations is an implicit object member function with no ref-qualifier and the type of object parameter of void f(this void); is void which is different from the type of the object parameter of void f(); which is A&. That is, the former has void as its object parameter while the latter has A&.

Thus both basic.scope.scope#3 and basic.scope.scope#4.4 are violated and hence the program is well-formed. As of now gcc is the only compiler accepting this and other three compilers rejects this.

I think the rejecting compiler are incorrectly taking dcl.fct#4.sentence-4 into account which says:

A parameter list consisting of a single unnamed parameter of non-dependent type void is equivalent to an empty parameter list.

To my understanding this dcl.fct#4 cannot be used here in our program because the object parameters are compared directly without any void or cv-qualifier adjustments. I mean in basic.scope.scope#3 we're not comparing the parameter-type-list but instead comparing the object parameters directly(with reference removal).

So it should be made clear if, void adjustment, cv-qualifer adjustment are also supposed to be applied here along with reference removal. To my understanding dcl.fct#4 is not to be used here because basic.scope.scope#3 explicitly only mentioned reference removal.

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