I understand that the literal operators for complex numbers for C++14
faltered at least in part because of the perceived ugliness of the float
operator:
constexpr complex<float>
operator"" i_f(); // fugly
The obvious choice
constexpr complex<float>
operator"" if();
failed because 'if' is a keyword. The 'if' keyword can never be exposed
in this context either by usage in a literal or by explicit call.
Allowing keywords as literal operator suffixes turns out to be a 6-liner
if gcc. I actually think *disallowing* them is a bit of a bug. (Not
sure if it was me or the standard).
I don't know if that's the wording but I just wanted to offer a working
implementation of the idea.
Ed
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c (revision 200158)
+++ gcc/cp/parser.c (working copy)
@@ -12359,6 +12358,13 @@
return cp_literal_operator_id (name);
}
}
+ else if (token->type == CPP_KEYWORD)
+ {
+ id = ridpointers [(int) token->keyword];
+ cp_lexer_consume_token (parser->lexer);
+ const char *name = IDENTIFIER_POINTER (id);
+ return cp_literal_operator_id (name);
+ }
else
{
error ("expected suffix identifier");