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