diff options
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/include/clang/AST/RecursiveASTVisitor.h | 4 | ||||
| -rw-r--r-- | clang/unittests/Tooling/RecursiveASTVisitorTest.cpp | 8 | ||||
| -rw-r--r-- | clang/unittests/Tooling/TestVisitor.h | 8 |
3 files changed, 17 insertions, 3 deletions
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h index 2e56a486f3d..60d75957061 100644 --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -2141,7 +2141,9 @@ DEF_TRAVERSE_STMT(BlockExpr, { return true; // no child statements to loop through. }) DEF_TRAVERSE_STMT(ChooseExpr, { }) -DEF_TRAVERSE_STMT(CompoundLiteralExpr, { }) +DEF_TRAVERSE_STMT(CompoundLiteralExpr, { + TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc())); +}) DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, { }) DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, { }) DEF_TRAVERSE_STMT(CXXDefaultArgExpr, { }) diff --git a/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp b/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp index 4b539067b13..1952c7b2118 100644 --- a/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp +++ b/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp @@ -392,4 +392,12 @@ TEST(RecursiveASTVisitor, VisitsExtension) { "int s = __extension__ (s);\n")); } +TEST(RecursiveASTVisitor, VisitsCompoundLiteralType) { + TypeLocVisitor Visitor; + Visitor.ExpectMatch("struct S", 1, 26); + EXPECT_TRUE(Visitor.runOver( + "int f() { return (struct S { int a; }){.a = 0}.a; }", + TypeLocVisitor::Lang_C)); +} + } // end namespace clang diff --git a/clang/unittests/Tooling/TestVisitor.h b/clang/unittests/Tooling/TestVisitor.h index d439d81d89e..63571d35adf 100644 --- a/clang/unittests/Tooling/TestVisitor.h +++ b/clang/unittests/Tooling/TestVisitor.h @@ -37,9 +37,13 @@ public: virtual ~TestVisitor() { } + enum Language { Lang_C, Lang_CXX }; + /// \brief Runs the current AST visitor over the given code. - bool runOver(StringRef Code) { - return tooling::runToolOnCode(CreateTestAction(), Code); + bool runOver(StringRef Code, Language L = Lang_CXX) { + // FIXME: The input language is determined based on the provided filename. + static const StringRef Filenames[] = { "input.c", "input.cc" }; + return tooling::runToolOnCode(CreateTestAction(), Code, Filenames[L]); } bool shouldVisitTemplateInstantiations() const { |

