[cfe-commits] [PATCH] Allow RecursiveASTVisitor to visit implicit ctor initializers (for which isWritten() returns false)

James Dennett reviews at llvm-reviews.chandlerc.com
Thu Aug 23 15:45:02 PDT 2012


  Now to work out how to upload v2 of the patch...


================
Comment at: unittests/Tooling/RecursiveASTVisitorTest.cpp:414-415
@@ +413,4 @@
+  EXPECT_TRUE(Visitor.runOver(
+      "struct WithCtor { WithCtor(); }; \n"
+      "struct Simple { Simple(); WithCtor w; }; \n"
+      "int main() { Simple s; Simple t(s); }\n"));
----------------
Richard Smith wrote:
> A comment explaining the purpose of the declarations of the default constructors would be useful. Alternatively, how about passing Simple &s as an argument to your function below, or using an "extern Simple s" global?
The latest version of the patch (soon to be uploaded) drops the copy from s to t and describes the role of the default constructors.

================
Comment at: unittests/Tooling/RecursiveASTVisitorTest.cpp:413-416
@@ +412,6 @@
+  // to use them in order to force them to appear in the AST.
+  EXPECT_TRUE(Visitor.runOver(
+      "struct WithCtor { WithCtor(); }; \n"
+      "struct Simple { Simple(); WithCtor w; }; \n"
+      "int main() { Simple s; Simple t(s); }\n"));
+}
----------------
Manuel Klimek wrote:
> I'd probably quickly add a EXPECT_FALSE for everything but the copy constructor, so that we are actually sure the test passes for the right reason.
The test passes because the visitor visits the implicit (un-written) construction of a WithCtor object -- nothing else satisfies the expectations.  I've added another test that a suitable visitors does *not* visit it (because it's implicit, and that visitor skips implicit code).


http://llvm-reviews.chandlerc.com/D26



More information about the cfe-commits mailing list