DWARF Debugging Standard Wiki |
---|
For detail description of the feature, please refer to:
http://en.wikipedia.org/wiki/C%2B%2B0x#Strongly_typed_enumerations
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2347.pdf
Current C++ enums are not type-safe. This is because an enumeration type is promoted to an integer by integral promotion.
enum Color { ClrRed, ClrOrange, ClrYellow, ClrGreen, ClrBlue, ClrViolet };
enum Alert { CndGreen, CndYellow, CndRed };
Color c = ClrRed;
Alert a = CndGreen;
bool armWeapons = ( a >= ClrYellow ); // Compiles okay, but not desirable
A new strongly-type enum is therefore created: enum class
. There is no
implicit conversion between enum class
and int
. And the underlying
type is always well-specified.
enum class A { A1=1 }; // underlying type is int by default
enum class B: unsigned long { B1=1 }; // underlying type is unsigned long
enum class
introduces its own scope. The names of enumerators are in
the enum’s scope, and are not injected into the enclosing scope.
enum class E { E1, E2, E3 = 100, E4 /* = 101 */ };
E e1 = E1; // error
E e2 = E::E2; // ok
New DWARF attribute
DW_AT_enum_class 0x70 flag A strongly typed enumeration type
5.8 Enumeration Type Entries
If an enumeration type has type-safe semantics such that:
then the enumeration type may have a DW_AT_enum_class
attribute
specifying those semantics. The value of this attribute is a flag.
In C++0x, a type declared using enum class
is a ‘strongly typed
enumeration type’, and would be represented with this attribute.
enum class E { E1, E2=100 };
E e1;
11$: DW_TAG_enumeration_type
DW_AT_name("E")
DW_AT_type(reference to base type "int")
DW_AT_enum_class(yes)
12$: DW_TAG_enumerator
DW_AT_name("E1")
DW_AT_const_value(0)
13$: DW_TAG_enumerator
DW_AT_name("E2")
DW_AT_const_value(100)
14$: DW_TAG_variable
DW_AT_name("e1")
DW_AT_type(reference to 11$)
May 7, 2009.
DW_TAG_strong_enumueration_type
, in favor of
DW_AT_enum_class
DW_AT_enum_class
June 3, 2009.
June 8, 2009.
July 2, 2009.
dwarfstd.org is supported by Sourceware. Contributions are welcome.
All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest © 2007-2022 by DWARF Standards Committee. |