This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-12-19


2641. Redundant specification of value category of literals

Section: 5.13  [lex.literal]     Status: C++23     Submitter: Andrey Erokhin     Date: 2022-11-07

[Accepted as a DR at the November, 2022 meeting.]

Subclause 7.5.2 [expr.prim.literal] paragraph 1 specifies:

... A string-literal is an lvalue designating a corresponding string literal object (5.13.5 [lex.string]), a user-defined-literal has the same value category as the corresponding operator call expression described in 5.13.9 [lex.ext], and any other literal is a prvalue.

Yet, there is redundant specification in 5.13.2 [lex.icon] paragraph 3:

The type of an integer-literal is the first type in the list in Table 9 corresponding to its optional integer-suffix in which its value can be represented. An integer-literal is a prvalue.

And in 5.13.7 [lex.bool] paragraph 1:

The Boolean literals are the keywords false and true. Such literals are prvalues and have type bool.

And in 5.13.8 [lex.nullptr] paragraph 1:

The pointer literal is the keyword nullptr. It is a prvalue of type std::nullptr_t.

Proposed resolution (approved by CWG 2022-11-10):

  1. Change in 5.13.1 [lex.literal.kinds] paragraph 1 as follows:

    There are several kinds of literals. [ Footnote: ... ]
    literal:
        integer-literal
        character-literal
        floating-point-literal
        string-literal
        boolean-literal
        pointer-literal
        user-defined-literal
    
    [ Note: When appearing as an expression, a literal has a type and a value category (7.5.2 [expr.prim.literal]). -- end note ]
  2. Change in 5.13.2 [lex.icon] paragraph 3 as follows:

    The type of an integer-literal is the first type in the list in Table 9 corresponding to its optional integer-suffix in which its value can be represented. An integer-literal is a prvalue.
  3. Change in 5.13.7 [lex.bool] paragraph 1 as follows:

    The Boolean literals are the keywords false and true. Such literals are prvalues and have type bool.
  4. Change in 5.13.8 [lex.nullptr] paragraph 1 as follows:

    The pointer literal is the keyword nullptr. It is a prvalue of has type std::nullptr_t.