[PATCH] D100346: [Clang] String Literal and Wide String Literal Encoding from the Preprocessor

ThePhD via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 12 19:29:50 PDT 2021


ThePhD marked an inline comment as done.
ThePhD added a comment.

In D100346#2684705 <https://reviews.llvm.org/D100346#2684705>, @rsmith wrote:

> Exposing this information seems fine to me. I think it'd be more useful to expose it in a way the preprocessor can inspect ...

The reason it's done like this is because the linked patches are going to use iconv, and iconv (while maintaining a fixed set of encodings it can support with canonical names that can be passed to its tools) can have encodings of arbitrary name added to it. If the eventual `-f(wide-?)exec-charset` options just pass-through to iconv, it's fair to say any translation we do will become out of date or unsuitable on a given platform. That's why I just want to expose the name! I did the same thing for GCC's functionality.

Microsoft is a bit luckier in that they have a closed set of encodings and a stable mapping between Name <-> Code Page Identifier, but they don't even cover the same list of encodings as iconv covers in its default distribution. Corentin Jabot's https://wg21.link/p1885 gives a canonical mapping, but again it's a closed-set of mappings and iconv is inherently extensible (at the "I rebuilt the library and installed it on my OS" level)!

The string literals work for people because, despite not being preprocessor-comparable, they can be manipulated at compile-time and switched on in the usual ways at `constexpr` time. See usages in:

https://github.com/soasis/text/blob/main/include/ztd/text/detail/encoding_name.hpp#L198
https://github.com/soasis/text/blob/main/include/ztd/text/literal.hpp#L54

, which can be used at compile-time like:

https://github.com/soasis/text/blob/main/tests/basic_compile_time/source/validate_code_points.cpp#L45



================
Comment at: clang/test/Preprocessor/init.c:122-123
 // COMMON:#define __clang_version__ {{.*}}
+// COMMON:#define __clang_literal_encoding__ {{.*}}
+// COMMON:#define __clang_wide_literal_encoding__ {{.*}}
 // COMMON:#define __llvm__ 1
----------------
rsmith wrote:
> Please add documentation to `docs/LanguageExtensions.rst` for these.
Done and dusted!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100346/new/

https://reviews.llvm.org/D100346



More information about the cfe-commits mailing list