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

Shafik Yaghmour via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 20 22:51:21 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) {
+      return true;
----------------
shafik wrote:

I don't like that we changed this to return `true` while in the location we moved this from it was returning `false`. This goes back to the name not really explain what this does, so it is not clear what the return value really represents. 

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


More information about the cfe-commits mailing list