[clang] Fix false negative when value initializing a field annotated with [[clang::require_field_initialization]] (PR #124329)

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 10 07:46:59 PST 2025


alexfh wrote:

It looks like this commit introduces an undesired false-positive: https://gcc.godbolt.org/z/rEjzK63he

```
struct P {
  int a [[clang::require_explicit_initialization]];
};

struct S {
  P p;
  S(P p) : p(p) {}
};
```

```
<source>:7:12: warning: field in 'P' requires explicit initialization but is not explicitly initialized [-Wuninitialized-explicit-init]
    7 |   S(P p) : p(p) {}
      |            ^
<source>:2:7: note: 'a' declared here
    2 |   int a [[clang::require_explicit_initialization]];
      |       ^
```

I don't think it's helpful to warn about not explicitly initializing a field on copy or move.

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


More information about the cfe-commits mailing list