On 09/19/2011 10:07 PM, Ed Smith-Rowland wrote:
On 09/19/2011 05:11 PM, Jason Merrill wrote:
Can't you store the string and the suffix, and then interpret the
number later if you end up calling an operator that takes the value?
I could and I thought abut it but from the wording (2.14.8 p3 and p4) it
looks like the numeric argument gets first try, then raw literal then
literal template. I thought I might as well let the preprocessor do the
numeric conversion since I'll always check it first.
Fair enough. We could do the overload resolution before we produce the
actual value to be passed, but I guess that's probably not a sufficient
optmization to bother with.
+ error ("user-defined literal operator template %q+D"
+ " conflicts with user-defined raw literal operator %q+D",
+ newdecl, olddecl);
You should only use + for one of the decls; that sets the source
position for the diagnostic.
+ TK(CHAR_USERDEF, LITERAL) /* 'char'_suffix - C++-0x */ \
+ TK(WCHAR_USERDEF, LITERAL) /* L'char'_suffix - C++-0x */ \
+ TK(CHAR16_USERDEF, LITERAL) /* u'char'_suffix - C++-0x */ \
+ TK(CHAR32_USERDEF, LITERAL) /* U'char'_suffix - C++-0x */ \
+ TK(STRING_USERDEF, LITERAL) /* "string"_suffix - C++-0x */ \
+ TK(WSTRING_USERDEF, LITERAL) /* L"string"_suffix - C++-0x */ \
+ TK(STRING16_USERDEF, LITERAL) /* u"string"_suffix - C++-0x */ \
+ TK(STRING32_USERDEF, LITERAL) /* U"string"_suffix - C++-0x */ \
+ TK(UTF8STRING_USERDEF,LITERAL) /* u8"string"_suffix - C++-0x */ \
Could we avoid adding all these additional codes by setting a flag on
the token? It seems odd to have extra codes for char/string literals
but not for numbers.
+ const char *suffix;
+ cpp_get_userdef_suffix (tok->val.str, '\'', &suffix);
Let's return the suffix pointer instead of passing in the address of a
local variable. And pass in the token pointer rather than the string
and a delimiter; libcpp can figure out which delimiter to use based on
the token type. It could also handle the flag I suggested above so that
the front end doesn't need to know about it.
Jason