[cfe-dev] Nested forward declarations of self
Richard Smith
richard at metafoo.co.uk
Thu Dec 13 19:23:22 PST 2012
On Thu, Dec 13, 2012 at 12:13 PM, Kim Gräsman <kim.grasman at gmail.com> wrote:
> Hello,
>
> When I try to use shouldVisitImplicitCode() with a
> RecursiveASTVisitor, I get some results I don't understand.
>
> I can reproduce this with the following code, modelled after
> ToolingTests/RecursiveASTVisitorTest.cpp;
>
> --
> class ImplicitCXXRecordDeclVisitor
> : public TestVisitor<ImplicitCXXRecordDeclVisitor> {
> public:
> bool shouldVisitImplicitCode() const { return true; }
>
> bool VisitDecl(Decl* Decl) {
> llvm::errs() << "Dumping decl at " << Decl << " of kind " <<
> Decl->getDeclKindName() << ", with " <<
> std::distance(Decl->redecls_begin(), Decl->redecls_end()) << "
> redecls.\n";
> Decl->dump(llvm::errs());
> llvm::errs() << "\n";
> return true;
> }
> };
>
> TEST(RecursiveASTVisitor, DumpRecordDecl) {
> ImplicitCXXRecordDeclVisitor Visitor;
> Visitor.runOver(
> "class A {}; \n");
> }
> --
>
> Given the minimal class definition, "class A {};", I get the following
> output (skipping over less relevant decls):
>
> --
> ...
> Dumping decl at 0xbac8b0 of kind CXXRecord, with 1 redecls.
> class A {
> class A;
> }
> Dumping decl at 0xbac990 of kind CXXRecord, with 1 redecls.
> class A
> --
>
> I'm surprised by the nested forward declaration in the class -- it
> seems like it creates a nested forward declaration to itself.
>
> Should it be there?
>
> I'd like to skip over it, any ideas on how I can identify these?
RecordDecl::isInjectedClassName().
More information about the cfe-dev
mailing list