[clang] Add Clang attribute to ensure that fields are initialized explicitly (PR #102040)

via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 25 03:04:40 PST 2024


higher-performance wrote:

@AaronBallman  Oh no worries at all. I'm actually struggling with something else -- apparently C++20 aggregate initialization with parentheses isn't handled correctly, and I'm struggling to get it to work. I added a bunch of test cases that all fail... any chance you know how these need to be handled?

I tried adding
```
  if (Args.empty()) {
    if (FieldDecl *FD = dyn_cast_if_present<FieldDecl>(Entity.getDecl())) {
      if (FD->hasAttr<ExplicitInitAttr>()) {
        S.Diag(Kind.getLocation(), diag::warn_field_requires_explicit_init)
            << /* Var-in-Record */ 0 << FD;
        S.Diag(FD->getLocation(), diag::note_entity_declared_at) << FD;
      }
    }
  }
```
to the beginning of `InitializationSequence::Perform`, but that also duplicated some of the errors, and still failed to handle some other cases (I think value-initialization?)...

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


More information about the cfe-commits mailing list