[clang] [Clang][Sema] Diagnosis for constexpr constructor not initializing a union member (PR #81042)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 8 03:40:06 PST 2024
================
@@ -2393,6 +2393,25 @@ static bool CheckConstexprFunctionBody(Sema &SemaRef, const FunctionDecl *Dcl,
Kind))
return false;
}
+ } else if (!Constructor->isDelegatingConstructor()) {
+ for (const Decl *decl : RD->decls()) {
+ if (const auto *inner = dyn_cast<CXXRecordDecl>(decl)) {
+ if (inner->isUnion()) {
+ 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 false;
+ }
----------------
mahtohappy wrote:
by unify you mean, put the check in the new function and call it at that place?
https://github.com/llvm/llvm-project/pull/81042
More information about the cfe-commits
mailing list