[clang] [Clang][Sema] Diagnosis for constexpr constructor not initializing a union member (PR #81225)

via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 21 06:47:37 PST 2024


================
@@ -2471,6 +2480,23 @@ static bool CheckConstexprFunctionBody(Sema &SemaRef, const FunctionDecl *Dcl,
   return true;
 }
 
+static bool
+checkUnionConstructorIntializer(Sema &SemaRef, const FunctionDecl *Dcl,
+                                const CXXConstructorDecl *Constructor,
+                                const CXXRecordDecl *RD,
+                                Sema::CheckConstexprKind Kind) {
+  if (Constructor->getNumCtorInitializers() == 0 && RD->hasVariantMembers()) {
+    if (Kind == Sema::CheckConstexprKind::Diagnose) {
+      SemaRef.Diag(Dcl->getLocation(),
+                   SemaRef.getLangOpts().CPlusPlus20
+                       ? diag::warn_cxx17_compat_constexpr_union_ctor_no_init
+                       : diag::ext_constexpr_union_ctor_no_init);
+    } else if (!SemaRef.getLangOpts().CPlusPlus20) {
----------------
mahtohappy wrote:

It checks if in a templated class/struct there's a union member than at least one member of that is initialized by the constexpr constructor. It's a warning, but in C++20 it's okay.
 

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


More information about the cfe-commits mailing list