diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -192,6 +192,8 @@ Fixes `Issue 56310 `_. - Clang will now look through type sugar when checking a member function is a move assignment operator. Fixes `Issue 56456 `_. +- Fixed a crash when a variable with a bool enum type that has no definition + used in comparison operators. Fixes `Issue 56560 `_. Improvements to Clang's diagnostics ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -16209,7 +16209,10 @@ ED->setIntegerTypeSourceInfo(TI); else ED->setIntegerType(QualType(EnumUnderlying.get(), 0)); - ED->setPromotionType(ED->getIntegerType()); + QualType EnumTy = ED->getIntegerType(); + ED->setPromotionType(EnumTy->isPromotableIntegerType() + ? Context.getPromotedIntegerType(EnumTy) + : EnumTy); } } else { // struct/union New = RecordDecl::Create(Context, Kind, SearchDC, KWLoc, Loc, Name, @@ -16831,8 +16834,11 @@ if (TypeSourceInfo *TI = EnumUnderlying.dyn_cast()) ED->setIntegerTypeSourceInfo(TI); else - ED->setIntegerType(QualType(EnumUnderlying.get(), 0)); - ED->setPromotionType(ED->getIntegerType()); + ED->setIntegerType(QualType(EnumUnderlying.get(), 0)); + QualType EnumTy = ED->getIntegerType(); + ED->setPromotionType(EnumTy->isPromotableIntegerType() + ? Context.getPromotedIntegerType(EnumTy) + : EnumTy); assert(ED->isComplete() && "enum with type should be complete"); } } else { diff --git a/clang/test/CXX/conv/conv.prom/p4.cpp b/clang/test/CXX/conv/conv.prom/p4.cpp --- a/clang/test/CXX/conv/conv.prom/p4.cpp +++ b/clang/test/CXX/conv/conv.prom/p4.cpp @@ -26,3 +26,10 @@ // FIXME: DR1407 will make this ill-formed e = +false_ // desired-error {{conversion from 'int' to 'bool'}} }; + +namespace GH56560 { +enum GH56560_1 : bool; +bool GH56560_2(GH56560_1 a, GH56560_1 b) { + return a == b; +} +} // namespace GH56560