[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

Danny Mösch via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 14 13:08:16 PST 2024


================
@@ -0,0 +1,130 @@
+// RUN: %check_clang_tidy -std=c++17 %s modernize-use-designated-initializers %t
+// RUN: %check_clang_tidy -check-suffixes=,SINGLE-ELEMENT -std=c++17 %s modernize-use-designated-initializers %t \
+// RUN:     -- -config="{CheckOptions: [{key: modernize-use-designated-initializers.IgnoreSingleElementAggregates, value: false}]}" \
+// RUN:     --
+// RUN: %check_clang_tidy -check-suffixes=POD -std=c++17 %s modernize-use-designated-initializers %t \
+// RUN:     -- -config="{CheckOptions: [{key: modernize-use-designated-initializers.RestrictToPODTypes, value: true}]}" \
+// RUN:     --
+
+struct S1 {};
+
----------------
SimplyDanny wrote:

Added option with two tests. It's very strict though. As soon as an element in a list stems from a macro, it will be ignored. Not sure how to check whether a macro describes a whole expression or list element, because these cases would be fine, e.g.

```c++
#define A (3+2)
#define B .j=1

S s {A, B};
```

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


More information about the cfe-commits mailing list