C++工作草案的措辞可能有缺陷(整数转换等级规则)

我在标准 C++的工作草案中发现了一个可能的矛盾。我首先陈述事实,我的问题在最后。

整数转换等级建立时,[conv.rank]/1.1表示

任何两个有符号整数类型 [...] 不应具有相同的整数转换等级,即使它们具有相同的表示。

[basic.fundamental]/8说:

Typewchar_t是一种独特的类型,它具有实现定义的有符号或无符号整数类型作为其基础类型。

最后,[conv.rank]/1.8:

的行列char8_tchar16_tchar32_t,和wchar_t应等于其基础类型的行列([basic.fundamental])。

如果它wchar_t被实现为有符号整数类型,它将与它的底层类型具有相同的等级,它是一些其他整数类型的不同类型。

因此,我们有两个具有相同等级的不同有符号整数类型,与 [conv.rank]/1.1 相矛盾。

这是一个实际的矛盾,还是我误解了 C++ 中两个可简单复制的类型是不同的类型?

回答

我们有两种不同的有符号整数类型

我在标准中没有看到它说这wchar_t是“有符号整数类型”。或“无符号整数类型”。我看到它说它是“整数类型”的地方:

类型 bool、char、wchar_t、char8_t、char16_t、char32_t,以及有符号和无符号整数类型统称为整型。整数类型的同义词是整数类型。

但是“有符号整数类型”的定义不包括wchar_t. 也就是说,该标准明确允许存在既不是“有符号整数类型”也不是“无符号整数类型”的“整数类型”。

来自 [conv.rank] 的声明不适用于此类类型。

  • @Aconcagua I have been convinced by Nicol Bolas, since it seems tht **signed integer types** and **unsigned integer types** are mere names of certain classes of integer types. The underlying type of `char8_t` is `unsigned char`, but the classification of `char8_t` is not **unsigned integer type**, but just another integer type.

以上是C++工作草案的措辞可能有缺陷(整数转换等级规则)的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>