[clang-tools-extra] [clang-tidy][NFC] Add trailing-comma tests for implicit init lists (PR #240341)

via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 9 03:47:28 PST 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-tools-extra

Author: Björn Svensson (bjosv)

<details>
<summary>Changes</summary>

Adds tests for two `readability-trailing-comma` false positives fixed by #<!-- -->215934 but not covered by its tests:

- Array-element designators without braces, e.g `.u64[1] = 1`.
- Arguments to a `__transparent_union__` parameter, e.g. glibc's `bind(fd, &a, len)`, where the fix-it removed the comma between arguments.

Both scenarios failed with clang-tidy 23.1.0 but pass from 23.1.1 (and main).

---
Full diff: https://github.com/llvm/llvm-project/pull/240341.diff


1 Files Affected:

- (modified) clang-tools-extra/test/clang-tidy/checkers/readability/trailing-comma.c (+33) 


``````````diff
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/trailing-comma.c b/clang-tools-extra/test/clang-tidy/checkers/readability/trailing-comma.c
index 9498fead9fcdaf..48e92681621a13 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/trailing-comma.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/trailing-comma.c
@@ -166,3 +166,36 @@ struct Outer nd3 = {
 // CHECK-FIXES-NEXT:   .x = {.v = 1},
 // CHECK-FIXES-NEXT:   .y = {.v = 2},
 // CHECK-FIXES-NEXT: };
+
+union Big {
+  unsigned long long u64[2];
+  unsigned char u8[16];
+};
+
+union Big big1 = {
+  .u64[0] = 0x0000000000000002,
+  .u64[1] = 0x0100000000000000,
+};
+
+union Big big2 = {
+  .u64[0] = 0x0000000000000002,
+  .u64[1] = 0x0100000000000000
+};
+// CHECK-MESSAGES: :[[@LINE-2]]:31: warning: initializer list should have a trailing comma
+// CHECK-FIXES: union Big big2 = {
+// CHECK-FIXES-NEXT:   .u64[0] = 0x0000000000000002,
+// CHECK-FIXES-NEXT:   .u64[1] = 0x0100000000000000,
+// CHECK-FIXES-NEXT: };
+
+struct Addr { int family; };
+
+typedef union {
+  struct Addr *a;
+} AddrArg __attribute__((__transparent_union__));
+
+int bindAddr(AddrArg addr, int len);
+
+void transparentUnionArg(void) {
+  struct Addr a;
+  bindAddr(&a, 0);
+}

``````````

</details>


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


More information about the cfe-commits mailing list