https://github.com/zeyi2 created 
https://github.com/llvm/llvm-project/pull/243703

Found via CTIT on DuckDB project.

>From 7ee7b8bc6ff8b6463c278e47da9444cbda3c54c8 Mon Sep 17 00:00:00 2001
From: Zeyi Xu <[email protected]>
Date: Wed, 18 Nov 2026 02:46:20 +0000
Subject: [PATCH] [clang-tidy] Fix modernize-return-braced-init-list crash on
 variadic constructors

---
 .../modernize/ReturnBracedInitListCheck.cpp   |  5 +--
 clang-tools-extra/docs/ReleaseNotes.md        |  4 +++
 .../modernize/return-braced-init-list.cpp     | 36 +++++++++++++++++++
 3 files changed, 43 insertions(+), 2 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
index 9dd0e00f569887..4040a4d8581553 100644
--- a/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
@@ -114,8 +114,9 @@ void ReturnBracedInitListCheck::check(const 
MatchFinder::MatchResult &Result) {
     return;
 
   // Make sure that the ctor arguments match the declaration.
-  for (unsigned I = 0, NumParams = MatchedConstructExpr->getNumArgs();
-       I < NumParams; ++I) {
+  const unsigned NumParams =
+      MatchedConstructExpr->getConstructor()->getNumParams();
+  for (unsigned I = 0; I < NumParams; ++I) {
     if (const ParmVarDecl *VD =
             MatchedConstructExpr->getConstructor()->getParamDecl(I)) {
       const auto ArgType = MatchedConstructExpr->getArg(I)->getType();
diff --git a/clang-tools-extra/docs/ReleaseNotes.md 
b/clang-tools-extra/docs/ReleaseNotes.md
index 2566c24544d706..1e4629862d7517 100644
--- a/clang-tools-extra/docs/ReleaseNotes.md
+++ b/clang-tools-extra/docs/ReleaseNotes.md
@@ -325,6 +325,10 @@ infrastructure are described first, followed by 
tool-specific sections.
   `std::initializer_list` constructor, as the braced form could select a
   different constructor.
 
+- Improved {doc}`modernize-return-braced-init-list
+  <clang-tidy/checks/modernize/return-braced-init-list>` check by fixing a 
crash
+  when a returned constructor call passes arguments through an ellipsis.
+
 - Fixed a crash in {doc}`modernize-use-designated-initializers
   <clang-tidy/checks/modernize/use-designated-initializers>` when analyzing
   malformed code with nested classes and ambiguous initializer.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/return-braced-init-list.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/return-braced-init-list.cpp
index 9b251bed17da74..f0427d62bf4f17 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/return-braced-init-list.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/return-braced-init-list.cpp
@@ -333,3 +333,39 @@ Gaz hn3() {
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: avoid repeating the return type
   // CHECK-FIXES: return {x};
 }
+
+struct Variadic {
+  Variadic(int, ...);
+};
+
+Variadic variadicWithExtraArgs() {
+  return Variadic(0, 1, 2.0f);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: avoid repeating the return type
+  // CHECK-FIXES: return {0, 1, 2.0f};
+}
+
+Variadic variadicWithoutExtraArgs() {
+  return Variadic(0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: avoid repeating the return type
+  // CHECK-FIXES: return {0};
+}
+
+struct OnlyEllipsis {
+  OnlyEllipsis(...);
+};
+
+OnlyEllipsis onlyEllipsis() {
+  return OnlyEllipsis(1, 2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: avoid repeating the return type
+  // CHECK-FIXES: return {1, 2};
+}
+
+struct VariadicWithDefault {
+  VariadicWithDefault(int = 0, ...);
+};
+
+VariadicWithDefault variadicWithDefault() {
+  return VariadicWithDefault();
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: avoid repeating the return type
+  // CHECK-FIXES: return {};
+}

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

Reply via email to