Skip to content

Incorrect implicit underlying type for enums #1883

Open
@Saalvage

Description

@Saalvage
Brief Description

When a header includes an enum with an implicit value representation such as the following:

enum myEnum {
    myVal = 0xffffffff;
};

The BuiltinType of the generated Enumeration declaration is erroneously int and the correpsonding item is incorrect (it's (ulong)(int)0xffffffff).

After some digging, it appears the code responsible for setting the type is:

// Get the underlying integer backing the enum.
clang::QualType IntType = ED->getIntegerType();
E->type = WalkType(IntType, 0);
E->builtinType = static_cast<BuiltinType*>(WalkType(IntType, 0,
/*DesugarType=*/true));

int is returned by getIntegerType and the items are being incorrectly represented as above.
It appears EnumDecl is a type directly provided by clang, so this appears to be a bug in clang?
Explicitly specifying the value representation makes everything work as expected.

This is especially odd considering that the clang compiler correctly increases the underlying type's size (and uses unsigned int unless negative values are present):
https://godbolt.org/z/K8neMYrYT

OS: Windows 10

Target: MSVC

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions