Skip to content

Commit 1cdf1e6

Browse files
authored
[clang][Interp] Fix classifying enum types (#104582)
We used to always return PT_IntAP(s) for them.
1 parent 7417b4c commit 1cdf1e6

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

clang/lib/AST/Interp/Context.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ std::optional<PrimType> Context::classify(QualType T) const {
135135
if (T->isAnyComplexType() || T->isVectorType())
136136
return std::nullopt;
137137

138+
if (const auto *ET = T->getAs<EnumType>())
139+
return classify(ET->getDecl()->getIntegerType());
140+
138141
if (T->isSignedIntegerOrEnumerationType()) {
139142
switch (Ctx.getIntWidth(T)) {
140143
case 64:

clang/test/AST/Interp/enums.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,8 @@ constexpr EC getB() {
4848

4949

5050
static_assert(getB() == EC::B, "");
51+
52+
namespace B {
53+
enum E : bool { Zero, One };
54+
static_assert((int)(E)2 == 1, "");
55+
} // namespace B

0 commit comments

Comments
 (0)