Is every “normal” use of user-defined literals undefined behavior?

前端 未结 5 1761
遥遥无期
遥遥无期 2021-01-18 03:07

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

5条回答
  •  一生所求
    2021-01-18 03:31

    Given the literal with suffix _X, the grammar calls _X an "identifier".

    So, yes: the standard has, presumably inadvertently, made it impossible to create a UDT at global scope, or UDTs that start with a capital letter, in a well-defined program. (Note that the former is not something you generally want to do anyway!)

    This cannot be resolved editorially: the names of user-defined literals would have to have their own lexical "namespace" that prevented clashes with (for example) names of implementation-provided functions. In my opinion, though, it would have been nice for there to be a non-normative note somewhere, pointing out the consequences of these rules and pointing out that they are deliberate.

提交回复
热议问题