At [over.literal] I read, in the list of examples, that
double operator""_Bq(long double);
is valid, whereas
double operator"" _Bq(long double);
is ill-formed, which is apparently a consequence of the space right after ""
.
Now, from the linked page, I can easily get to [usrlit.suffix] with one click and I read that
Literal suffix identifiers that do not start with an underscore are reserved for future standardization.
Good, but where do I read why operator"" _Bq
is invalid?
I've also read the description of user-defined-string-literal
on cppreference, but to be honest I've found it a bit confusing.
Can anybody break that down with examples?
"" _Bq
is a string-literal followed by an identifier, whereas ""_Bq
is a user-defined-string-literal which is a single, distinct preprocessing token ([lex.pptoken]).
As a consequence, the former is affected by macro expansion, but the latter is not:
#define _x
int operator "" _x(char); // becomes `int operator "" (char);` which is invalid
int operator ""_x(char); // ok
That aside, both forms are allowed as part of a literal-operator-id and have the same meaning. However, since forming the first construct involves the use of a reserved identifier, it is ill-formed with no diagnostic required per [lex.name]/3 (motivation for this being that _Bq
could be in use by the implementation as a macro).
That's the intent, anyway. The current normative wording does not actually make that difference clear enough: user-defined-string-literal ultimately contains an identifier, and [lex.name]/3 has no indication that it only applies to identifiers that are themselves preprocessing tokens. This is the subject of CWG2521.