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

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 8 04:47:37 PST 2024


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

```suggestion
  if (isa<EnumType>(getType()))
    return getType();
  if (const auto *ECD = getEnumConstantDecl()) {
    const auto *ED = cast<EnumDecl>(ECD->getDeclContext());
    if (ED->isCompleteDefinition())
      return Ctx.getTypeDeclType(ED);
  }
```
No `else` after `return` via our coding standard, NFC

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


More information about the cfe-commits mailing list