Author: Timm Baeder Date: 2024-08-16T14:37:45+02:00 New Revision: 1cdf1e693425ae6830883d2fc0eaaa601a8250d8
URL: https://github.com/llvm/llvm-project/commit/1cdf1e693425ae6830883d2fc0eaaa601a8250d8 DIFF: https://github.com/llvm/llvm-project/commit/1cdf1e693425ae6830883d2fc0eaaa601a8250d8.diff LOG: [clang][Interp] Fix classifying enum types (#104582) We used to always return PT_IntAP(s) for them. Added: Modified: clang/lib/AST/Interp/Context.cpp clang/test/AST/Interp/enums.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/Context.cpp b/clang/lib/AST/Interp/Context.cpp index 92ac28137fdb45..e9c1fd1b8dc9f9 100644 --- a/clang/lib/AST/Interp/Context.cpp +++ b/clang/lib/AST/Interp/Context.cpp @@ -135,6 +135,9 @@ std::optional<PrimType> Context::classify(QualType T) const { if (T->isAnyComplexType() || T->isVectorType()) return std::nullopt; + if (const auto *ET = T->getAs<EnumType>()) + return classify(ET->getDecl()->getIntegerType()); + if (T->isSignedIntegerOrEnumerationType()) { switch (Ctx.getIntWidth(T)) { case 64: diff --git a/clang/test/AST/Interp/enums.cpp b/clang/test/AST/Interp/enums.cpp index c4db7875451677..459cf3a0c83d54 100644 --- a/clang/test/AST/Interp/enums.cpp +++ b/clang/test/AST/Interp/enums.cpp @@ -48,3 +48,8 @@ constexpr EC getB() { static_assert(getB() == EC::B, ""); + +namespace B { + enum E : bool { Zero, One }; + static_assert((int)(E)2 == 1, ""); +} // namespace B _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits