Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class types are not cv-qualified #4250

Closed
jabelloc opened this issue Sep 29, 2020 · 9 comments
Closed

Class types are not cv-qualified #4250

jabelloc opened this issue Sep 29, 2020 · 9 comments

Comments

@jabelloc
Copy link

[class.derived]/2:

A class-or-decltype shall denote a (possibly cv-qualified) class type that is not an incompletely defined class ([class.mem]); any cv-qualifiers are ignored. ...

This should be replaced by:

A class-or-decltype shall denote a (possibly cv-qualified) class type that is not an incompletely defined class ([class.mem]); any cv-qualifiers are ignored. ...

@jensmaurer
Copy link
Member

Uh, why? A cv-qualified class type is still a class type. For example, this works:

struct B {};
using CB = const B;
struct D : CB { };

@jabelloc
Copy link
Author

But this doesn't work (at least clang, GCC and VS reject the code), as there is no way for the compiler to parse the const below, given the C++ grammar.

struct B{};
struct D : const B {};

So, I presume that your snippet compiles because the CB in struct D : CB {} doesn't carry the const anymore. Although I still need to take a look into this in the Standard.

@jwakely
Copy link
Member

jwakely commented Sep 30, 2020

No, it compiles because of [class.derived] p2, and it would stop working with your change.

@jwakely
Copy link
Member

jwakely commented Sep 30, 2020

In other words, "any cv-qualifiers are ignored" in [class.derived] p2 is what causes "doesn't carry the const anymore" to be true, so don't try to remove those words!

@jabelloc
Copy link
Author

@jwakely

Could you tell me which grammar production would allow the compiler to parse the const in struct D : const B{}; above?

@jabelloc
Copy link
Author

@jwakely I can see what you mean now.

@jwakely
Copy link
Member

jwakely commented Sep 30, 2020

I meant Jens's snippet when I said "it compiles", because that's the one that compiles. Yours doesn't compile.

In his example, the class-or-decltype CB denotes a const-qualified class type. When used as a base class, any cv-qualifiers are ignored, so the base class is B. That's what [class.derived] p2 means. Changing [class.derived] p2 would break the example, and so is not only non-editorial, but completely wrong.

What part of this is confusing you?

@jabelloc
Copy link
Author

As I said before I have already understood your point. But to avoid misunderstandings about this paragraph I would surely insert the Note below, as follows:

A class-or-decltype shall denote a (possibly cv-qualified) class type that is not an incompletely defined
class (11.4); any cv-qualifiers are ignored. [Note: the code below compiles

struct B {};
using CB = const B;
struct D : CB { };

-end note] The class denoted by ...

@jensmaurer
Copy link
Member

Since "struct D: const B" is syntactically invalid, this is the only remaining choice, with no need for further elaboration. The standard is not a tutorial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants