[clang] Add Clang attribute to ensure that fields are initialized explicitly (PR #102040)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 20 13:21:11 PST 2024
================
@@ -3141,6 +3148,10 @@ def warn_attribute_ignored_no_calls_in_stmt: Warning<
"statement">,
InGroup<IgnoredAttributes>;
+def warn_attribute_needs_aggregate : Warning<
----------------
higher-performance wrote:
Thanks so much for the review!
For `warn_field_requires_explicit_init`, I'm thinking maybe it shouldn't be an error by default, because it is really only relevant for code that will be executed. i.e. the following should not be an error:
```
// external_dep_1.h
struct S { int x; int y [[clang::requires_explicit_initialization]]; };
// external_dep_2.h
#include "external_dep_1.h"
inline S make_s(int x) { S s = {x}; return s; }
inline int get_default() { return 42; }
// main.cpp
#include "external_dep_1.h"
#include "external_dep_2.h"
int main() {
return get_default();
}
```
If we demand users to modify a third-party `external_dep_2.h` just because _another_ third-party dependency happened to initialize a field in a later version `external_dep_2.h` wasn't previously compiled with, that would frustrate users. And I think most likely it would cause them to demote the error to a warning anyway.
https://github.com/llvm/llvm-project/pull/102040
More information about the cfe-commits
mailing list