c++ - 这是(枚举 : char {}) a gcc bug?

标签 c++ gcc c++11 enums

在 gcc-4.5 下打印 0,在 gcc-4.6 下打印 1。

#include <iostream>

enum VenueId: char {}; 
int
main (int argc, char ** argv)
{
  VenueId v = (VenueId)'P';
  std::cout << (v=='P') << std::endl;
  return 0;
}

最佳答案

根据标准,VenuedId 具有 char 类型作为基础类型,因此 v 应包含 char 'P'v == 'P' 应该产生 true

§ 7.2 枚举声明

Each enumeration defines a type that is different from all other types. Each enumeration also has an underlying type. The underlying type can be explicitly specified using enum-base; if not explicitly specified, the underlying type of a scoped enumeration type is int. In these cases, the underlying type is said to be fixed. Following the closing brace of an num-specifier, each enumerator has the type of its enumeration.

关于c++ - 这是(枚举 : char {}) a gcc bug?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19423626/

相关文章:

c++ - 拥有一张 map 的 map 还是一张非常大的 map 更有效率?

c++ - Linux中加载时链接与运行时链接期间的符号地址

c++ - std::promise 能否知道相应的 std::future 已取消等待?

c++ - 内存管理容器设计问题 - 项目需要继承

c++ - 多个枚举值的一个模板特化

c++ - 替换文件扩展名时崩溃

c++ - 如何理解*(void **)(&m_handle)= dlsym (“./haldle_lib.so”, “custom_func”);

c++ - Boost Spirit 词法分析器状态异花授粉

multithreading - 不同平台的奇怪多线程输出

c++ - 由于符号与 abi::cxx11 的链接问题?