User defined literals must start with an underscore.
This is a more or less universally well-known rule that you can find on every layman-worded site talkin
This is a good question, and I'm not sure about the answer, but I think the answer is "no, it's not UB" based on a particular reading of the standard.
[lex.name]/3.2 reads:
Each identifier that begins with an underscore is reserved to the implementation for use as a name in the global namespace.
Now, clearly, the restriction "as a name in the global namespace" should be read as applying to the entire rule, not just to how the implementation may use the name. That is, its meaning is not
"each identifier that begins with an underscore is reserved to the implementation, AND the implementation may use such identifiers as names in the global namespace"
but rather,
"the use of any identifier that begins with an underscore as a name in the global namespace is reserved to the implementation".
(If we believed the first interpretation, then it would mean that no one could declare a function called my_namespace::_foo
, for example.)
Under the second interpretation, something like a global declaration of operator""_foo
(in the global scope) is legal, because such a declaration does not use _foo
as a name. Rather, the identifier is just a part of the actual name, which is operator""_foo
(which does not start with an underscore).