Closed jengelh closed 2 years ago
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 functionconst
...
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.
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: