[clang] [clang] Fix implicit integer conversion for opaque enums declared in class templates (PR #121039)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 6 13:53:45 PST 2025


=?utf-8?q?André?= Brand <andre.brand at mailbox.org>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/121039 at github.com>


================
@@ -1571,6 +1571,23 @@ Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) {
         Enum->setIntegerType(SemaRef.Context.IntTy);
       else
         Enum->setIntegerTypeSourceInfo(NewTI);
+
+      // The following lines are relevant for opaque-enum-declarations.
+      // If users declare a full enum-specifier, the promotion type is reset
+      // again when parsing the (potentially empty) enumerator-list.
+      // We implement the same logic from C++11 [conv.prom] p4 here but only
+      // after template specialization [temp.spec.general] because it requires
+      // the concrete type.
+      // Note that (1) this also correctly handles the non-dependent case,
+      // (2) we set the promotion type for scoped enumerations to ensure
+      // consistency with declarations outside of templates, (3) we guarantee a
+      // valid promotion even if the user provided an invalid underlying type
+      // (fallback to "default int").
----------------
cor3ntin wrote:

```suggestion
      // C++23 [conv.prom]p4
      // if integral promotion can be applied to its underlying type, a prvalue of an unscoped enumeration type 
      // whose underlying type is fixed can also be converted to a prvalue of the promoted underlying type.
      // 
      // FIXME: that logic is already implemented in ActOnEnumBody, factor out into (Re)BuildEnumBody. 
```

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


More information about the cfe-commits mailing list