xref: /llvm-project/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-fmt.cpp (revision 42dfaa15a60cea6cd75a2efb419aa2c206d2a127)
1 // RUN: %check_clang_tidy %s modernize-use-std-format %t -- \
2 // RUN:   -config="{CheckOptions: { \
3 // RUN:              modernize-use-std-format.StrictMode: true, \
4 // RUN:              modernize-use-std-format.StrFormatLikeFunctions: 'fmt::sprintf', \
5 // RUN:              modernize-use-std-format.ReplacementFormatFunction: 'fmt::format', \
6 // RUN:              modernize-use-std-format.FormatHeader: '<fmt/core.h>' \
7 // RUN:            }}" \
8 // RUN:   -- -isystem %clang_tidy_headers
9 
10 // CHECK-FIXES: #include <fmt/core.h>
11 #include <string>
12 
13 namespace fmt
14 {
15 template <typename S, typename... T,
16           typename Char = char>
17 std::basic_string<Char> sprintf(const S& fmt, const T&... args);
18 } // namespace fmt
19 
20 std::string fmt_sprintf_simple() {
21   return fmt::sprintf("Hello %s %d", "world", 42);
22   // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'fmt::format' instead of 'sprintf' [modernize-use-std-format]
23   // CHECK-FIXES: fmt::format("Hello {} {}", "world", 42);
24 }
25