]> granicus.if.org Git - clang/commitdiff
Part of PR13618: visit the TypeLoc when RecursiveASTVisitor visits a CompoundLiteralExpr.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 17 Aug 2012 21:23:17 +0000 (21:23 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 17 Aug 2012 21:23:17 +0000 (21:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162133 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/RecursiveASTVisitor.h
unittests/Tooling/RecursiveASTVisitorTest.cpp
unittests/Tooling/TestVisitor.h

index 2e56a486f3d0bb2432b21fa04ddb5296d54a12cc..60d759570610587ac3f7618c449783d1537ffc91 100644 (file)
@@ -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, { })
index 4b539067b136df1703e6d8845a5d3fe6b7ebc646..1952c7b21188e8697de901dc2d48c4d69e7ee946 100644 (file)
@@ -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
index d439d81d89ef4134efa590248258d593ab0ff410..63571d35adfb3004ed500c5033136f75522f9a69 100644 (file)
@@ -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 {