File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 7
7
// ===----------------------------------------------------------------------===//
8
8
#include " ParsedAST.h"
9
9
#include " refactor/Tweak.h"
10
+ #include " clang/AST/ASTContext.h"
10
11
#include " clang/AST/Stmt.h"
11
12
#include " clang/Basic/LangOptions.h"
12
13
#include " clang/Basic/SourceLocation.h"
@@ -43,6 +44,12 @@ class RawStringLiteral : public Tweak {
43
44
44
45
REGISTER_TWEAK (RawStringLiteral)
45
46
47
+ static bool isFeatureAvailable (const ASTContext &Context) {
48
+ // Raw strings are available only for C++11 or later versions, and they are
49
+ // not available for C.
50
+ return Context.getLangOpts ().CPlusPlus11 ;
51
+ }
52
+
46
53
static bool isNormalString (const StringLiteral &Str, SourceLocation Cursor,
47
54
SourceManager &SM) {
48
55
// All chunks must be normal ASCII strings, not u8"..." etc.
@@ -72,6 +79,9 @@ static bool canBeRaw(llvm::StringRef Content) {
72
79
}
73
80
74
81
bool RawStringLiteral::prepare (const Selection &Inputs) {
82
+ if (!isFeatureAvailable (Inputs.AST ->getASTContext ())) {
83
+ return false ;
84
+ }
75
85
const SelectionTree::Node *N = Inputs.ASTSelection .commonAncestor ();
76
86
if (!N)
77
87
return false ;
Original file line number Diff line number Diff line change @@ -36,6 +36,20 @@ 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( const char *a = ^"^f^o^o^\^n^";)c" );
44
+ }
45
+
46
+ TEST_F (RawStringLiteralTest, TestCpp98) {
47
+ Context = File;
48
+ ExtraArgs = {" -std=c++98" }; // raw strings are unavailable
49
+ // in versions prior to C++11
50
+ EXPECT_UNAVAILABLE (R"cpp( const char *a = ^"^f^o^o^\^n^";)cpp" );
51
+ }
52
+
39
53
} // namespace
40
54
} // namespace clangd
41
55
} // namespace clang
You can’t perform that action at this time.
0 commit comments