[Bug c++/106426] New: UTF-8 character literals do not have unsigned type in the preprocessor in -fchar8_t mode

tom at honermann dot net gcc-bugzilla@gcc.gnu.org
Sun Jul 24 16:48:12 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106426

            Bug ID: 106426
           Summary: UTF-8 character literals do not have unsigned type in
                    the preprocessor in -fchar8_t mode
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tom at honermann dot net
  Target Milestone: ---

As demonstrated at https://godbolt.org/z/7xzWEbqb5, UTF-8 character literals in
preprocessor directives are given the same type as ordinary character literals
(`char` with signed or unsigned behavior dependent on target or use of the
`-fsigned-char` or `-funsigned-char` option) in `char8_t` modes.  In `char8_t`
enabled modes (C++20 by default or when `-fchar8_t` is used), such literals
should be treated as unsigned.

$ cat t.cpp
#if u8'\0' - 1 < 0
#error "UTF-8 character literals not unsigned in preprocessor"
#endif

$ gcc -c -std=c++17 -fchar8_t t.cpp
t.cpp:2:2: error: #error "UTF-8 character literals not unsigned in
preprocessor"
    2 | #error "UTF-8 character literals not unsigned in preprocessor"
      |  ^~~~~

$ gcc -c -std=c++20 t.cpp
t.cpp:2:2: error: #error "UTF-8 character literals not unsigned in
preprocessor"
    2 | #error "UTF-8 character literals not unsigned in preprocessor"
      |  ^~~~~


More information about the Gcc-bugs mailing list