Author: Zeyi Xu Date: 2026-03-27T17:13:43+08:00 New Revision: 93e475a47583aa539dd886c2794766ce42b24a30
URL: https://github.com/llvm/llvm-project/commit/93e475a47583aa539dd886c2794766ce42b24a30 DIFF: https://github.com/llvm/llvm-project/commit/93e475a47583aa539dd886c2794766ce42b24a30.diff LOG: [clang-tidy] Add missing #include insertion in macros for modernize-use-std-print (#188394) Follow-up of: #188247 --------- Co-authored-by: Victor Chernyakin <[email protected]> Added: clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-macro.cpp Modified: clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp clang-tools-extra/docs/ReleaseNotes.rst Removed: ################################################################################ diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp index 0f612471497a7..6d18ebeae6ce4 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp @@ -158,7 +158,8 @@ void UseStdPrintCheck::check(const MatchFinder::MatchResult &Result) { if (MaybeHeaderToInclude) Diag << IncludeInserter.createIncludeInsertion( - Result.Context->getSourceManager().getFileID(PrintfCall->getBeginLoc()), + Result.SourceManager->getFileID( + Result.SourceManager->getExpansionLoc(PrintfCall->getBeginLoc())), *MaybeHeaderToInclude); } diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index f8550e72dcc85..97b2ffdd9557b 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -326,6 +326,11 @@ Changes in existing checks - Added missing ``#include`` insertion when the format function call appears as an argument to a macro. +- Improved :doc:`modernize-use-std-print + <clang-tidy/checks/modernize/use-std-print>` check by adding missing + ``#include`` insertion when the format function call appears as an + argument to a macro. + - Improved :doc:`modernize-use-trailing-return-type <clang-tidy/checks/modernize/use-trailing-return-type>` check by fixing spurious ``missing '(' after '__has_feature'`` errors caused by builtin diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-macro.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-macro.cpp new file mode 100644 index 0000000000000..387f6ccfaf427 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-macro.cpp @@ -0,0 +1,12 @@ +// RUN: %check_clang_tidy -std=c++23-or-later %s modernize-use-std-print %t + +#include <cstdio> +// CHECK-FIXES: #include <print> + +#define WRAP_MSG(msg) msg + +void macro_argument_include(int n) { + WRAP_MSG(printf("value %d", n)); + // CHECK-MESSAGES: [[@LINE-1]]:12: warning: use 'std::print' instead of 'printf' [modernize-use-std-print] + // CHECK-FIXES: WRAP_MSG(std::print("value {}", n)); +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
