1 | // RUN: %check_clang_tidy %s modernize-use-std-format %t -- \ |
2 | // RUN: -config="{CheckOptions: \ |
3 | // RUN: { \ |
4 | // RUN: modernize-use-std-format.StrFormatLikeFunctions: 'MyClass::StrFormat', \ |
5 | // RUN: modernize-use-std-format.ReplacementFormatFunction: 'format', \ |
6 | // RUN: } \ |
7 | // RUN: }" \ |
8 | // RUN: -- -isystem %clang_tidy_headers |
9 | |
10 | #include <cstdio> |
11 | #include <string.h> |
12 | #include <string> |
13 | |
14 | struct MyClass |
15 | { |
16 | template <typename S, typename... Args> |
17 | std::string StrFormat(const S &format, const Args&... args); |
18 | }; |
19 | |
20 | std::string StrFormat_simple(MyClass &myclass, MyClass *pmyclass) { |
21 | std::string s; |
22 | |
23 | s += myclass.StrFormat(format: "MyClass::StrFormat dot %d" , args: 42); |
24 | // CHECK-MESSAGES: [[@LINE-1]]:8: warning: use 'format' instead of 'StrFormat' [modernize-use-std-format] |
25 | // CHECK-FIXES: s += myclass.format("MyClass::StrFormat dot {}", 42); |
26 | |
27 | s += pmyclass->StrFormat(format: "MyClass::StrFormat pointer %d" , args: 43); |
28 | // CHECK-MESSAGES: [[@LINE-1]]:8: warning: use 'format' instead of 'StrFormat' [modernize-use-std-format] |
29 | // CHECK-FIXES: s += pmyclass->format("MyClass::StrFormat pointer {}", 43); |
30 | |
31 | s += (*pmyclass).StrFormat(format: "MyClass::StrFormat deref pointer %d" , args: 44); |
32 | // CHECK-MESSAGES: [[@LINE-1]]:8: warning: use 'format' instead of 'StrFormat' [modernize-use-std-format] |
33 | // CHECK-FIXES: s += (*pmyclass).format("MyClass::StrFormat deref pointer {}", 44); |
34 | |
35 | return s; |
36 | } |
37 | |
38 | struct MyDerivedClass : public MyClass {}; |
39 | |
40 | std::string StrFormat_derived(MyDerivedClass &derived) { |
41 | return derived.StrFormat(format: "MyDerivedClass::StrFormat dot %d" , args: 42); |
42 | // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'format' instead of 'StrFormat' [modernize-use-std-format] |
43 | // CHECK-FIXES: return derived.format("MyDerivedClass::StrFormat dot {}", 42); |
44 | } |
45 | |