llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-tools-extra Author: Zeyi Xu (zeyi2) <details> <summary>Changes</summary> Found via CTIT on DuckDB project. --- Full diff: https://github.com/llvm/llvm-project/pull/243703.diff 3 Files Affected: - (modified) clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp (+3-2) - (modified) clang-tools-extra/docs/ReleaseNotes.md (+4) - (modified) clang-tools-extra/test/clang-tidy/checkers/modernize/return-braced-init-list.cpp (+36) ``````````diff 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 {}; +} `````````` </details> https://github.com/llvm/llvm-project/pull/243703 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
