[clang] Add Clang attribute to ensure that fields are initialized explicitly (PR #102040)
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 9 03:02:43 PDT 2024
================
@@ -2133,6 +2142,18 @@ void CXXRecordDecl::completeDefinition(CXXFinalOverriderMap *FinalOverriders) {
for (conversion_iterator I = conversion_begin(), E = conversion_end();
I != E; ++I)
I.setAccess((*I)->getAccess());
+
+ ASTContext &Context = getASTContext();
+ if (!Context.getLangOpts().CPlusPlus20 && hasUserDeclaredConstructor()) {
+ // Diagnose any aggregate behavior changes in C++20
+ for (field_iterator I = field_begin(), E = field_end(); I != E; ++I) {
+ if (const auto *attr = I->getAttr<ExplicitAttr>()) {
+ Context.getDiagnostics().Report(
+ getLocation(), diag::warn_cxx20_compat_aggregate_init_with_ctors)
----------------
ilya-biryukov wrote:
Should we add a new warning here?
`"Attribute [[clang:...]] will have no effect in C++20 as the type will be non-aggregate due to user-declared constructors"`.
The wording for an existing attribute suggests there is already some initialization of this type happening, which is not necessarily the case.
https://github.com/llvm/llvm-project/pull/102040
More information about the cfe-commits
mailing list