[clang] [Clang] Implement CWG2598: Union of non-literal types (PR #78195)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 16 07:22:45 PST 2024
================
@@ -1383,6 +1383,34 @@ void CXXRecordDecl::addedMember(Decl *D) {
}
}
+bool CXXRecordDecl::isLiteral() const {
+ const LangOptions &LangOpts = getLangOpts();
+ if (!(LangOpts.CPlusPlus20 ? hasConstexprDestructor()
+ : hasTrivialDestructor()))
+ return false;
+
+ if (isLambda() && !LangOpts.CPlusPlus17)
+ return false;
+
+ if (hasNonLiteralTypeFieldsOrBases()) {
+ // CWG2598
+ // is an aggregate union type that has either no variant
+ // members or at least one variant member of non-volatile literal type,
+ if (!isUnion())
+ return false;
+ bool HasAtLeastOneLiteralMember =
+ fields().empty() || any_of(fields(), [this](const FieldDecl *D) {
+ return !D->getType().isVolatileQualified() &&
+ D->getType()->isLiteralType(getASTContext());
+ });
+ if (!HasAtLeastOneLiteralMember)
+ return false;
+ }
+
+ return isAggregate() || isLambda() || hasConstexprNonCopyMoveConstructor() ||
----------------
erichkeane wrote:
Should these conditions be moved 'above' the union stuff? I would think they are 'cheaper'. Also, I see the 'isLambda' here, despite it only being in C++17 mode on line 1392.
https://github.com/llvm/llvm-project/pull/78195
More information about the cfe-commits
mailing list