Because there are no negative integer literals in the grammar. Let's put aside the user-defined nature of your question. When we write -12
, it's the literal 12
, which has unary -
applied to it. The grammatical definition of an integer literal contains no mention of a minus sign.
[lex.icon] (redacted and edited)
integer-literal:
decimal-literal integer-suffix
decimal-literal:
nonzero-digit
decimal-literal digit
nonzero-digit: one of
1 2 3 4 5 6 7 8 9
digit: one of
0 1 2 3 4 5 6 7 8 9
It's right there in the grammar. There are no productions that produce negative integer literal. And that is why user-defined literals follow the same convention. Their grammar production simply reuses the production for an integer literal
[lex.ext]
user-defined-literal:
user-defined-integer-literal
user-defined-integer-literal:
decimal-literal ud-suffix
Since negation is always an expression other than a literal, you need to overload the appropriate operator for coord_t
. And by the way, the same applies for +12
. It's a unary plus applied to 12
, not a literal by itself.