Does the C++ standard mandate an encoding for wchar_t?

后端 未结 7 2146
礼貌的吻别
礼貌的吻别 2021-02-10 07:09

Here are some excerpts from my copy of the 2014 draft standard N4140

22.5 Standard code conversion facets [locale.stdcvt]

3 F

7条回答
  •  忘了有多久
    2021-02-10 07:49

    Both your interpretations are incorrect. The standard doesn't require that there be a single wchar_t encoding, just like it doesn't require a single char encoding. The codecvt_utf8 facet must convert between UTF-8 and UCS-2 or UCS-4. This true even UTF-8, UCS-2, and UCS-4 are not supported as character sets in any locale.

    If Elem is of type wchar_t and isn't big enough to store a UCS-2 value than then the conversion operations of the codecvt_utf8 facet are undefined because the standard doesn't say what happens in that case. If it is big enough (or if you want to argue that the standard requires that it must be big enough) then it's merely implementation defined whether the UCS-2 or UCS-4 wchar_t values the facet generates or consumes are in an encoding compatible with any locale defined wchar_t encoding.

提交回复
热议问题