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 @@ -16194,7 +16194,11 @@ ED->setIntegerTypeSourceInfo(TI); else ED->setIntegerType(QualType(EnumUnderlying.get(), 0)); - ED->setPromotionType(ED->getIntegerType()); + QualType EnumTy = ED->getIntegerType(); + if (EnumTy->isPromotableIntegerType()) + ED->setPromotionType(Context.getPromotedIntegerType(EnumTy)); + else + ED->setPromotionType(EnumTy); } } else { // struct/union New = RecordDecl::Create(Context, Kind, SearchDC, KWLoc, Loc, Name, @@ -16816,8 +16820,12 @@ 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(); + if (EnumTy->isPromotableIntegerType()) + ED->setPromotionType(Context.getPromotedIntegerType(EnumTy)); + else + ED->setPromotionType(EnumTy); assert(ED->isComplete() && "enum with type should be complete"); } } else { diff --git a/clang/test/SemaCXX/enum-bool.cpp b/clang/test/SemaCXX/enum-bool.cpp new file mode 100644 --- /dev/null +++ b/clang/test/SemaCXX/enum-bool.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -fsyntax-only %s + +// This shouldn't crash. + +enum GH56560_1 : bool; +bool GH56560_2(GH56560_1 a, GH56560_1 b) { + return a == b; +}