User Defined Literal naming in C++

Viewed 125

In a recent code review I came across the following:

constexpr Dimensionless operator"" _(...) {}

In my reading of the standard I cannot work out if this is UB, unspecified behaviour, or underspecified behaviour.

From 17.6.4.3.2 [global.names] we know that:

Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace.

and from 17.6.4.3.5 [usrlit.suffix] we know that UDLs are exempted:

Literal suffix identifiers that do not start with an underscore are reserved for future standardization.

My question is:

Does the standard allow for a literal that is only an underscore (42_)?

1 Answers

Does the standard allow for a literal that is only an underscore (42_)?

Yes.


As per [lex.ext] the grammar of a user-defined-literal, for all families of user-defined literals, is:

<family-specific grammar> ud-suffix

ud-suffix:
    identifier

[over.literal]/1 describes the limitations on the ud-suffix in the context of user-defined-string-literal:s:

[...] The ud-suffix of the user-defined-string-literal or the identifier in a literal-operator-id is called a literal suffix identifier. Some literal suffix identifiers are reserved for future standardization; see [usrlit.suffix].

with [usrlit.suffix]/1 highlighting that the ud-suffix must start with and underscore:

Literal suffix identifiers that do not start with an underscore are reserved for future standardization.

This does not, however, reject an ud-suffix that is only an underscore.

[lex.ext]/3, /4 and /6 contains the sole wording on non-string user-defined literals, and none rejects an ud-suffix that is only an underscore.

Related