paul-j-lucas/cdecl

Reword member function reference qualifiers

Closed this issue · 4 comments

This is a proposal for some new wording regarding member functions' cv-qualifiers and ref-qualifiers, stemming from a discussion I had on ##c++ IRC. For the following commands, I suggest new wording:

c++decl> explain int (K::*p)() const;
declare p as pointer to member of class K const-qualified member function returning int

c++decl> explain int (K::*p)() &;
declare p as pointer to member of class K lvalue-reference-qualified member function returning int

c++decl> explain int (K::*p)() &&;
declare p as pointer to member of class K rvalue-reference-qualified member function returning int

c++decl> explain int (K::*p)() const &&;
declare p as pointer to member of class K const-qualified rvalue-reference-qualified member function returning int

c++decl> explain int (K::*p)() volatile;
declare p as pointer to member of class K volatile-qualified member function returning int

Well, it's actually much simpler to add qualified as a noise word that the parser will ignore (when parsing English back into gibberish) rather than adding new hyphenated keywords, e.g.:

declare p as pointer to member of class K constant qualified member function returning int

It occurred to me that everything with const, volatile, &, or && is "qualified":

const int ci;  // ci is an int that is const qualified
int &ri = &i;  // ri is an int that is reference qualified

So it's not only functions.

Thinking about English used to describe C++ functions, something like:

void S::f() const

is referred to as a "const member function" in common spoken and written English. I'll grant that it may be the case that "const qualified" may be used in formal specifications, but it's not clear to me that it really adds any clarity to cdecl explanations.

That makes sense I guess.

One thing though. While const on int makes the int const, const on a function does not make the function const¹, but rather, the class instance (this).

¹ Code is immutable anyway, i.e. standard C and C++ have no provisions (that I know of) for modifying code without veering off into the land of undefined/implementation-defined behavior.

... const on a function does not make the function const ...

Yes, I know; which is why I wrote:

... is referred to as a "const member function" in common spoken and written English.

Emphasis on "common." So while it may not be strictly technically correct, it's what people say and write anyway and everybody knows what is meant.