[PATCH] D130210: [SemaCXX] Set promotion type for enum bool to integer type.

Zequan Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 21 10:11:02 PDT 2022


zequanwu updated this revision to Diff 446551.
zequanwu marked 2 inline comments as done.
zequanwu added a comment.

- Address comment.
- Move test to `clang/test/CXX/conv/conv.prom/p4.cpp`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130210/new/

https://reviews.llvm.org/D130210

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CXX/conv/conv.prom/p4.cpp


Index: clang/test/CXX/conv/conv.prom/p4.cpp
===================================================================
--- clang/test/CXX/conv/conv.prom/p4.cpp
+++ 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
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -16194,7 +16194,10 @@
           ED->setIntegerTypeSourceInfo(TI);
         else
           ED->setIntegerType(QualType(EnumUnderlying.get<const Type *>(), 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,
@@ -16816,8 +16819,11 @@
       if (TypeSourceInfo *TI = EnumUnderlying.dyn_cast<TypeSourceInfo*>())
         ED->setIntegerTypeSourceInfo(TI);
       else
-        ED->setIntegerType(QualType(EnumUnderlying.get<const Type*>(), 0));
-      ED->setPromotionType(ED->getIntegerType());
+        ED->setIntegerType(QualType(EnumUnderlying.get<const Type *>(), 0));
+      QualType EnumTy = ED->getIntegerType();
+      ED->setPromotionType(EnumTy->isPromotableIntegerType()
+                               ? Context.getPromotedIntegerType(EnumTy)
+                               : EnumTy);
       assert(ED->isComplete() && "enum with type should be complete");
     }
   } else {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130210.446551.patch
Type: text/x-patch
Size: 1878 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220721/6f98251f/attachment.bin>


More information about the cfe-commits mailing list