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

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).

From 4b3681eeaa07355ddb67fa548f8df90931311b1b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= <[email protected]>
Date: Mon, 9 Nov 2026 10:05:20 +0100
Subject: [PATCH] [clang-tidy][NFC] Add readability-trailing-comma tests for
 implicit init lists
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Add tests for two 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.

Signed-off-by: Björn Svensson <[email protected]>
---
 .../checkers/readability/trailing-comma.c     | 33 +++++++++++++++++++
 1 file changed, 33 insertions(+)

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);
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to