[clang] [Clang][Sema] Fix type of enumerators in incomplete enumerations (PR #84068)

via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 5 13:13:07 PST 2024


================
@@ -264,10 +264,13 @@ namespace {
 }
 
 QualType Expr::getEnumCoercedType(const ASTContext &Ctx) const {
-  if (isa<EnumType>(this->getType()))
+  if (isa<EnumType>(this->getType())) {
     return this->getType();
-  else if (const auto *ECD = this->getEnumConstantDecl())
-    return Ctx.getTypeDeclType(cast<EnumDecl>(ECD->getDeclContext()));
+  } else if (const auto *ECD = this->getEnumConstantDecl()) {
+    const auto *ED = cast<EnumDecl>(ECD->getDeclContext());
+    if (ED->isCompleteDefinition())
+      return Ctx.getTypeDeclType(ED);
+  }
   return this->getType();
----------------
Sirraide wrote:

Erm, is there a good reason why we’re doing `this->` here? I can see it was doing that before too, but it just seems really unnecessary to me...

https://github.com/llvm/llvm-project/pull/84068


More information about the cfe-commits mailing list