File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,12 @@ class RawStringLiteral : public Tweak {
43
43
44
44
REGISTER_TWEAK (RawStringLiteral)
45
45
46
+ static bool isFeatureAvailable (const Tweak::Selection &Inputs) {
47
+ // Raw strings are available only for C++11 or later versions, and they are
48
+ // not available for C.
49
+ return Inputs.AST ->getASTContext ().getLangOpts ().CPlusPlus11 ;
50
+ }
51
+
46
52
static bool isNormalString (const StringLiteral &Str, SourceLocation Cursor,
47
53
SourceManager &SM) {
48
54
// All chunks must be normal ASCII strings, not u8"..." etc.
@@ -76,7 +82,7 @@ bool RawStringLiteral::prepare(const Selection &Inputs) {
76
82
if (!N)
77
83
return false ;
78
84
Str = dyn_cast_or_null<StringLiteral>(N->ASTNode .get <Stmt>());
79
- return Str &&
85
+ return Str && isFeatureAvailable (Inputs) &&
80
86
isNormalString (*Str, Inputs.Cursor , Inputs.AST ->getSourceManager ()) &&
81
87
needsRaw (Str->getBytes ()) && canBeRaw (Str->getBytes ());
82
88
}
Original file line number Diff line number Diff line change @@ -36,6 +36,24 @@ literal)")cpp";
36
36
EXPECT_EQ (apply (Input), Output);
37
37
}
38
38
39
+ TEST_F (RawStringLiteralTest, TestC) {
40
+ Context = File;
41
+ FileName = " TestTU.c" ;
42
+ ExtraArgs = {" -xc" }; // raw strings are unavailable in C
43
+ EXPECT_UNAVAILABLE (R"c(
44
+ const char* a = "^f^o^o^\^n^";
45
+ )c" );
46
+ }
47
+
48
+ TEST_F (RawStringLiteralTest, TestCpp98) {
49
+ Context = File;
50
+ ExtraArgs = {" -std=c++98" }; // raw strings are unavailable
51
+ // in versions prior to C++11
52
+ EXPECT_UNAVAILABLE (R"cpp(
53
+ const char* a = "^f^o^o^\^n^";
54
+ )cpp" );
55
+ }
56
+
39
57
} // namespace
40
58
} // namespace clangd
41
59
} // namespace clang
You can’t perform that action at this time.
0 commit comments