modernize-raw-string-literal.cpp
5.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// RUN: %check_clang_tidy -std=c++11,c++14,c++17 %s modernize-raw-string-literal %t -- -config="{CheckOptions: [{key: modernize-raw-string-literal.ReplaceShorterLiterals, value: 1}]}"
// FIXME: Fix the checker to work in C++20 mode.
char const *const BackSlash("goink\\frob");
// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: escaped string literal can be written as a raw string literal [modernize-raw-string-literal]
// CHECK-FIXES: {{^}}char const *const BackSlash(R"(goink\frob)");{{$}}
char const *const PlainLiteral("plain literal");
// Non-printable ASCII characters.
char const *const Nul("goink\\\000");
char const *const Soh("goink\\\001");
char const *const Stx("goink\\\002");
char const *const Etx("goink\\\003");
char const *const Enq("goink\\\004");
char const *const Ack("goink\\\005");
char const *const Bell("goink\\\afrob");
char const *const BackSpace("goink\\\bfrob");
char const *const HorizontalTab("goink\\\tfrob");
char const *const NewLine("goink\nfrob");
char const *const VerticalTab("goink\\\vfrob");
char const *const FormFeed("goink\\\ffrob");
char const *const CarraigeReturn("goink\\\rfrob");
char const *const So("goink\\\016");
char const *const Si("goink\\\017");
char const *const Dle("goink\\\020");
char const *const Dc1("goink\\\021");
char const *const Dc2("goink\\\022");
char const *const Dc3("goink\\\023");
char const *const Dc4("goink\\\024");
char const *const Nak("goink\\\025");
char const *const Syn("goink\\\026");
char const *const Etb("goink\\\027");
char const *const Can("goink\\\030");
char const *const Em("goink\\\031");
char const *const Sub("goink\\\032");
char const *const Esc("goink\\\033");
char const *const Fs("goink\\\034");
char const *const Gs("goink\\\035");
char const *const Rs("goink\\\036");
char const *const Us("goink\\\037");
char const *const HexNonPrintable("\\\x03");
char const *const Delete("\\\177");
char const *const MultibyteSnowman("\xE2\x98\x83");
// CHECK-FIXES: {{^}}char const *const MultibyteSnowman("\xE2\x98\x83");{{$}}
char const *const TrailingSpace("A line \\with space. \n");
char const *const TrailingNewLine("A single \\line.\n");
char const *const AlreadyRaw(R"(foobie\\bletch)");
char const *const UTF8Literal(u8"foobie\\bletch");
char const *const UTF8RawLiteral(u8R"(foobie\\bletch)");
// TODO: enable these tests once all supported compilers
// support char16_t and char32_t (VS2013 does not)
// char16_t const *const UTF16Literal(u"foobie\\bletch");
// char16_t const *const UTF16RawLiteral(uR"(foobie\\bletch)");
// char32_t const *const UTF32Literal(U"foobie\\bletch");
// char32_t const *const UTF32RawLiteral(UR"(foobie\\bletch)");
wchar_t const *const WideLiteral(L"foobie\\bletch");
wchar_t const *const WideRawLiteral(LR"(foobie\\bletch)");
char const *const SingleQuote("goink\'frob");
// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: {{.*}} can be written as a raw string literal
// CHECK-XFIXES: {{^}}char const *const SingleQuote(R"(goink'frob)");{{$}}
char const *const DoubleQuote("goink\"frob");
// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: {{.*}} can be written as a raw string literal
// CHECK-FIXES: {{^}}char const *const DoubleQuote(R"(goink"frob)");{{$}}
char const *const QuestionMark("goink\?frob");
// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: {{.*}} can be written as a raw string literal
// CHECK-FIXES: {{^}}char const *const QuestionMark(R"(goink?frob)");{{$}}
char const *const RegEx("goink\\(one|two\\)\\\\\\?.*\\nfrob");
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: {{.*}} can be written as a raw string literal
// CHECK-FIXES: {{^}}char const *const RegEx(R"(goink\(one|two\)\\\?.*\nfrob)");{{$}}
char const *const Path("C:\\Program Files\\Vendor\\Application\\Application.exe");
// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: {{.*}} can be written as a raw string literal
// CHECK-FIXES: {{^}}char const *const Path(R"(C:\Program Files\Vendor\Application\Application.exe)");{{$}}
char const *const ContainsSentinel("who\\ops)\"");
// CHECK-MESSAGES: :[[@LINE-1]]:36: warning: {{.*}} can be written as a raw string literal
// CHECK-FIXES: {{^}}char const *const ContainsSentinel(R"lit(who\ops)")lit");{{$}}
char const *const ContainsDelim("whoops)\")lit\"");
// CHECK-MESSAGES: :[[@LINE-1]]:33: warning: {{.*}} can be written as a raw string literal
// CHECK-FIXES: {{^}}char const *const ContainsDelim(R"lit1(whoops)")lit")lit1");{{$}}
char const *const OctalPrintable("\100\\");
// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: {{.*}} can be written as a raw string literal
// CHECK-FIXES: {{^}}char const *const OctalPrintable(R"(@\)");{{$}}
char const *const HexPrintable("\x40\\");
// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: {{.*}} can be written as a raw string literal
// CHECK-FIXES: {{^}}char const *const HexPrintable(R"(@\)");{{$}}
char const *const prettyFunction(__PRETTY_FUNCTION__);
char const *const function(__FUNCTION__);
char const *const func(__func__);
#define TRICK(arg_) #arg_
char const *const MacroBody = TRICK(foo\\bar);
#define HAT(rabbit_) #rabbit_ "foo\\bar"
char const *const StringizedMacroArgument = HAT(foo\\bar);
#define SUBST(lit_) lit_
char const *const MacroArgument = SUBST("foo\\bar");
// FIXME: We should be able to replace this string literal macro argument
template <typename T>
void fn(char const *const Arg) {
char const *const Str("foo\\bar");
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: {{.*}} can be written as a raw string literal
// CHECK-FIXES: {{^}} char const *const Str(R"(foo\bar)");{{$}}
}
template <>
void fn<int>(char const *const Arg) {
char const *const Str("foo\\bar");
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: {{.*}} can be written as a raw string literal
// CHECK-FIXES: {{^}} char const *const Str(R"(foo\bar)");{{$}}
}
void callFn() {
fn<int>("foo\\bar");
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}} can be written as a raw string literal
// CHECK-FIXES: {{^}} fn<int>(R"(foo\bar)");{{$}}
fn<double>("foo\\bar");
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: {{.*}} can be written as a raw string literal
// CHECK-FIXES: {{^}} fn<double>(R"(foo\bar)");{{$}}
}