Skip to content

Commit 6c20314

Browse files
committed
[clang] Remove raw string literals in macros
Older (but still supported) versions of GCC don't handle C++11 raw string literals in macro parameters correctly.
1 parent ef5deba commit 6c20314

File tree

2 files changed

+96
-86
lines changed

2 files changed

+96
-86
lines changed

clang/unittests/AST/ASTTraverserTest.cpp

Lines changed: 83 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,7 @@ B func12() {
342342

343343
{
344344
auto FN = getFunctionNode("func1");
345-
346-
EXPECT_EQ(dumpASTString(ast_type_traits::TK_AsIs, FN),
347-
R"cpp(
345+
llvm::StringRef Expected = R"cpp(
348346
FunctionDecl 'func1'
349347
`-CompoundStmt
350348
`-ReturnStmt
@@ -354,129 +352,143 @@ FunctionDecl 'func1'
354352
`-ImplicitCastExpr
355353
`-CXXConstructExpr
356354
`-IntegerLiteral
357-
)cpp");
355+
)cpp";
358356

359-
EXPECT_EQ(
360-
dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource, FN),
361-
R"cpp(
357+
EXPECT_EQ(dumpASTString(ast_type_traits::TK_AsIs, FN), Expected);
358+
359+
Expected = R"cpp(
362360
FunctionDecl 'func1'
363361
`-CompoundStmt
364362
`-ReturnStmt
365363
`-IntegerLiteral
366-
)cpp");
364+
)cpp";
365+
EXPECT_EQ(
366+
dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource, FN),
367+
Expected);
367368
}
368369

369-
EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource,
370-
getFunctionNode("func2")),
371-
R"cpp(
370+
llvm::StringRef Expected = R"cpp(
372371
FunctionDecl 'func2'
373372
`-CompoundStmt
374373
`-ReturnStmt
375374
`-CXXTemporaryObjectExpr
376375
`-IntegerLiteral
377-
)cpp");
378-
376+
)cpp";
379377
EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource,
380-
getFunctionNode("func3")),
381-
R"cpp(
378+
getFunctionNode("func2")),
379+
Expected);
380+
381+
Expected = R"cpp(
382382
FunctionDecl 'func3'
383383
`-CompoundStmt
384384
`-ReturnStmt
385385
`-CXXFunctionalCastExpr
386386
`-IntegerLiteral
387-
)cpp");
388-
387+
)cpp";
389388
EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource,
390-
getFunctionNode("func4")),
391-
R"cpp(
389+
getFunctionNode("func3")),
390+
Expected);
391+
392+
Expected = R"cpp(
392393
FunctionDecl 'func4'
393394
`-CompoundStmt
394395
`-ReturnStmt
395396
`-CXXTemporaryObjectExpr
396-
)cpp");
397-
397+
)cpp";
398398
EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource,
399-
getFunctionNode("func5")),
400-
R"cpp(
399+
getFunctionNode("func4")),
400+
Expected);
401+
402+
Expected = R"cpp(
401403
FunctionDecl 'func5'
402404
`-CompoundStmt
403405
`-ReturnStmt
404406
`-CXXTemporaryObjectExpr
405-
)cpp");
406-
407+
)cpp";
407408
EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource,
408-
getFunctionNode("func6")),
409-
R"cpp(
409+
getFunctionNode("func5")),
410+
Expected);
411+
412+
Expected = R"cpp(
410413
FunctionDecl 'func6'
411414
`-CompoundStmt
412415
`-ReturnStmt
413416
`-CXXTemporaryObjectExpr
414-
)cpp");
415-
417+
)cpp";
416418
EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource,
417-
getFunctionNode("func7")),
418-
R"cpp(
419+
getFunctionNode("func6")),
420+
Expected);
421+
422+
Expected = R"cpp(
419423
FunctionDecl 'func7'
420424
`-CompoundStmt
421425
`-ReturnStmt
422426
`-CXXTemporaryObjectExpr
423-
)cpp");
424-
427+
)cpp";
425428
EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource,
426-
getFunctionNode("func8")),
427-
R"cpp(
429+
getFunctionNode("func7")),
430+
Expected);
431+
432+
Expected = R"cpp(
428433
FunctionDecl 'func8'
429434
`-CompoundStmt
430435
`-ReturnStmt
431436
`-CXXFunctionalCastExpr
432437
`-InitListExpr
433-
)cpp");
434-
438+
)cpp";
435439
EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource,
436-
getFunctionNode("func9")),
437-
R"cpp(
440+
getFunctionNode("func8")),
441+
Expected);
442+
443+
Expected = R"cpp(
438444
FunctionDecl 'func9'
439445
`-CompoundStmt
440446
`-ReturnStmt
441447
`-CXXFunctionalCastExpr
442448
`-InitListExpr
443-
)cpp");
444-
449+
)cpp";
445450
EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource,
446-
getFunctionNode("func10")),
447-
R"cpp(
451+
getFunctionNode("func9")),
452+
Expected);
453+
454+
Expected = R"cpp(
448455
FunctionDecl 'func10'
449456
`-CompoundStmt
450457
|-DeclStmt
451458
| `-VarDecl 'a'
452459
| `-CXXConstructExpr
453460
`-ReturnStmt
454461
`-DeclRefExpr 'a'
455-
)cpp");
456-
462+
)cpp";
457463
EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource,
458-
getFunctionNode("func11")),
459-
R"cpp(
464+
getFunctionNode("func10")),
465+
Expected);
466+
467+
Expected = R"cpp(
460468
FunctionDecl 'func11'
461469
`-CompoundStmt
462470
|-DeclStmt
463471
| `-VarDecl 'b'
464472
| `-CXXConstructExpr
465473
`-ReturnStmt
466474
`-DeclRefExpr 'b'
467-
)cpp");
468-
475+
)cpp";
469476
EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource,
470-
getFunctionNode("func12")),
471-
R"cpp(
477+
getFunctionNode("func11")),
478+
Expected);
479+
480+
Expected = R"cpp(
472481
FunctionDecl 'func12'
473482
`-CompoundStmt
474483
|-DeclStmt
475484
| `-VarDecl 'c'
476485
| `-CXXConstructExpr
477486
`-ReturnStmt
478487
`-DeclRefExpr 'c'
479-
)cpp");
488+
)cpp";
489+
EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource,
490+
getFunctionNode("func12")),
491+
Expected);
480492
}
481493

482494
TEST(Traverse, LambdaUnlessSpelledInSource) {
@@ -521,8 +533,7 @@ struct SomeStruct {
521533
{
522534
auto L = getLambdaNode("captures");
523535

524-
EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource, L),
525-
R"cpp(
536+
llvm::StringRef Expected = R"cpp(
526537
LambdaExpr
527538
|-DeclRefExpr 'a'
528539
|-DeclRefExpr 'b'
@@ -534,10 +545,11 @@ LambdaExpr
534545
|-ParmVarDecl 'h'
535546
| `-IntegerLiteral
536547
`-CompoundStmt
537-
)cpp");
548+
)cpp";
549+
EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource, L),
550+
Expected);
538551

539-
EXPECT_EQ(dumpASTString(ast_type_traits::TK_AsIs, L),
540-
R"cpp(
552+
Expected = R"cpp(
541553
LambdaExpr
542554
|-CXXRecordDecl ''
543555
| |-CXXMethodDecl 'operator()'
@@ -557,44 +569,48 @@ LambdaExpr
557569
| `-DeclRefExpr 'd'
558570
|-DeclRefExpr 'f'
559571
`-CompoundStmt
560-
)cpp");
572+
)cpp";
573+
EXPECT_EQ(dumpASTString(ast_type_traits::TK_AsIs, L), Expected);
561574
}
562575

563576
{
564577
auto L = getLambdaNode("templated");
565578

566-
EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource, L),
567-
R"cpp(
579+
llvm::StringRef Expected = R"cpp(
568580
LambdaExpr
569581
|-DeclRefExpr 'a'
570582
|-TemplateTypeParmDecl 'T'
571583
|-ParmVarDecl 't'
572584
`-CompoundStmt
573-
)cpp");
585+
)cpp";
586+
EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource, L),
587+
Expected);
574588
}
575589

576590
{
577591
auto L = getLambdaNode("capture_this");
578592

579-
EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource, L),
580-
R"cpp(
593+
llvm::StringRef Expected = R"cpp(
581594
LambdaExpr
582595
|-CXXThisExpr
583596
`-CompoundStmt
584-
)cpp");
597+
)cpp";
598+
EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource, L),
599+
Expected);
585600
}
586601

587602
{
588603
auto L = getLambdaNode("capture_this_copy");
589604

590-
EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource, L),
591-
R"cpp(
605+
llvm::StringRef Expected = R"cpp(
592606
LambdaExpr
593607
|-VarDecl 'self'
594608
| `-UnaryOperator
595609
| `-CXXThisExpr
596610
`-CompoundStmt
597-
)cpp");
611+
)cpp";
612+
EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource, L),
613+
Expected);
598614
}
599615
}
600616

clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,8 +1684,7 @@ void foo()
16841684
functionDecl(traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource,
16851685
hasAnyName("foo", "bar")))));
16861686

1687-
EXPECT_TRUE(
1688-
matches(R"cpp(
1687+
llvm::StringRef Code = R"cpp(
16891688
void foo(int a)
16901689
{
16911690
int i = 3.0 + a;
@@ -1694,21 +1693,14 @@ void bar()
16941693
{
16951694
foo(7.0);
16961695
}
1697-
)cpp",
1696+
)cpp";
1697+
EXPECT_TRUE(
1698+
matches(Code,
16981699
callExpr(traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource,
16991700
hasArgument(0, floatLiteral())))));
17001701

17011702
EXPECT_TRUE(
1702-
matches(R"cpp(
1703-
void foo(int a)
1704-
{
1705-
int i = 3.0 + a;
1706-
}
1707-
void bar()
1708-
{
1709-
foo(7.0);
1710-
}
1711-
)cpp",
1703+
matches(Code,
17121704
callExpr(traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource,
17131705
hasAnyArgument(floatLiteral())))));
17141706

@@ -1722,13 +1714,14 @@ void bar()
17221714
functionDecl(hasName("foo"), traverse(ast_type_traits::TK_AsIs,
17231715
hasDescendant(floatLiteral())))));
17241716

1725-
EXPECT_TRUE(
1726-
matches(R"cpp(
1717+
Code = R"cpp(
17271718
void foo()
17281719
{
17291720
int i = (3);
17301721
}
1731-
)cpp",
1722+
)cpp";
1723+
EXPECT_TRUE(
1724+
matches(Code,
17321725
traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource,
17331726
varDecl(hasInitializer(integerLiteral(equals(3)))))));
17341727
}
@@ -1744,13 +1737,14 @@ TEST(Traversal, traverseWithBinding) {
17441737
// Some existing matcher code expects to take a matcher as a
17451738
// template arg and bind to it. Verify that that works.
17461739

1747-
EXPECT_TRUE(matcherTemplateWithBinding(
1748-
R"cpp(
1740+
llvm::StringRef Code = R"cpp(
17491741
int foo()
17501742
{
17511743
return 42.0;
17521744
}
1753-
)cpp",
1745+
)cpp";
1746+
EXPECT_TRUE(matcherTemplateWithBinding(
1747+
Code,
17541748
traverse(ast_type_traits::TK_AsIs,
17551749
returnStmt(has(implicitCastExpr(has(floatLiteral())))))));
17561750
}

0 commit comments

Comments
 (0)