[lex.ext] (original) (raw)
5 Lexical conventions [lex]
5.13 Literals [lex.literal]
5.13.8 User-defined literals [lex.ext]
If a token matches both user-defined-literal and another literal kind, it is treated as the latter.
[Example 1:
— _end example_]
The syntactic non-terminal preceding the ud-suffix in auser-defined-literal is taken to be the longest sequence of characters that could match that non-terminal.
To determine the form of this call for a given user-defined-literal L with ud-suffix X, the literal-operator-id whose literal suffix identifier is X is looked up in the context of L using the rules for unqualified name lookup.
Let S be the set of declarations found by this lookup.
S shall not be empty.
If L is a user-defined-integer-literal, let n be the literal without its ud-suffix.
If S contains a literal operator with parameter type unsigned long long, the literal L is treated as a call of the formoperator "" X(_n_ULL)
Otherwise, S shall contain a raw literal operator or a numeric literal operator template ([over.literal]) but not both.
If S contains a raw literal operator, the literal L is treated as a call of the formoperator "" X("n")
Otherwise (S contains a numeric literal operator template),L is treated as a call of the formoperator "" X<'', '', ... ''>() where n is the source character sequence .
[Note 1:
The sequence can only contain characters from the basic source character set.
— _end note_]
If L is a user-defined-floating-point-literal, let f be the literal without its ud-suffix.
If S contains a literal operator with parameter type long double, the literal L is treated as a call of the formoperator "" X(_f_L)
Otherwise, S shall contain a raw literal operator or a numeric literal operator template ([over.literal]) but not both.
If S contains a raw literal operator, the literal L is treated as a call of the formoperator "" X("f")
Otherwise (S contains a numeric literal operator template),L is treated as a call of the formoperator "" X<'', '', ... ''>() where f is the source character sequence .
[Note 2:
The sequence can only contain characters from the basic source character set.
— _end note_]
If L is a user-defined-string-literal, let str be the literal without its ud-suffixand let len be the number of code units in str(i.e., its length excluding the terminating null character).
If S contains a literal operator template with a non-type template parameter for which str is a well-formed template-argument, the literal L is treated as a call of the formoperator "" X<_str_>()
Otherwise, the literal L is treated as a call of the formoperator "" X(str, len)
If L is a user-defined-character-literal, let ch be the literal without its ud-suffix.
S shall contain a literal operator whose only parameter has the type of ch and the literal L is treated as a call of the formoperator "" X(ch)
[Example 2: long double operator "" _w(long double); std::string operator "" _w(const char16_t*, std::size_t);unsigned operator "" _w(const char*);int main() { 1.2_w; u"one"_w; 12_w; "two"_w; } — _end example_]
During concatenation, ud-suffixes are removed and ignored and the concatenation process occurs as described in [lex.string].
At the end of phase 6, if a string-literal is the result of a concatenation involving at least oneuser-defined-string-literal, all the participatinguser-defined-string-literals shall have the same ud-suffixand that suffix is applied to the result of the concatenation.
[Example 3: int main() { L"A" "B" "C"_x; "P"_x "Q" "R"_y; } — _end example_]