cplusplus / CWG

Core Working Group
24 stars 7 forks source link

Does the text "class type" intends to mention all related types or merely cv-unqualified version #265

Open xmh0511 opened 1 year ago

xmh0511 commented 1 year ago

Full name of submitter (unless configured in github; will be published with the issue): Jim X

[basic.type.qualifier] says:

Each type other than a function or reference type is part of a group of four distinct, but related, types: a cv-unqualified version, a const-qualified version, a volatile-qualified version, and a const-volatile-qualified version.

So, when we use "class type or enumeration type", do we intend to mean all related types or just the cv-unqualified version? There are many wordings in the document use "class type or enumeration type" with different meanings.

For example [over.match.oper] p1

If no operand of an operator in an expression has a type that is a class or an enumeration, the operator is assumed to be a built-in operator and interpreted according to [expr.compound].

In this context, "class or enumeration" should mention all versions of that type.

[dcl.init.general] p16.6

Otherwise, if the destination type is a (possibly cv-qualified) class type:

In this context, "class type" only refers to the cv-unqualified version.

As mentioned in https://github.com/cplusplus/draft/issues/5351,

[basic.lookup.qual.general] p2

The lookup context of a member-qualified name is the type of its associated object expression

The type can be cv T where T is a class type. [basic.lookup.qual.general] p3 says

Qualified name lookup in a class, namespace, or enumeration performs a search of the scope associated with it ([class.member.lookup]) except as specified below.

The "a class" should refer to the cv-unqualified class type since [basic.scope.class] p1 says

Any declaration of a class or class template C introduces a class scope

A class-specifier introduces a class type, which is a cv-unqualified type.

Suggested resolution

We should uniform the meaning of the text "class type" and "enumeration type". The text is reasonable to only name the cv-unqualified version type that is introduced by the class or enumeration declaration. In everywhere, we want to mentioned all related types, we should say: (possibly cv-qualified) that type

frederick-vs-ja commented 1 year ago

See CWG2448 and CWG2689. Although the issue is a bit more complicated for class and enumeration types, because scopes and intruducing declarations are involved.

xmh0511 commented 1 year ago

See CWG2448 and CWG2689. Although the issue is a bit more complicated for class and enumeration types, because scopes and intruducing declarations are involved.

The concise way is, we say "class type" or "enumeration type" are these types introduced by the corresponding declaration, which are cv-unqualified types. This thought conforms with name lookup rules:

Qualified name lookup in a class, namespace, or enumeration performs a search of the scope associated with it ([class.member.lookup]) except as specified below.

The "a class" is the type introduced by the class declaration, which introduces a cv-unqualified type, hence the associated scope of "a class" is the scope introduced by the class declaration.

jensmaurer commented 1 year ago

The standard is certainly imprecise about when we mean "cv T" (i.e. possibly cv-qualified type) and when we don't. I agree that the outcome of a class definition is a cv-unqualified type, so we need to drop cv-qualifiers somewhere along the name lookup process.