From 32ef52063c207054911a9e0435cc85330faf2ee3 Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Mon, 14 Jan 2019 17:16:00 +0000 Subject: [AST] Fix double-traversal of code in top-level lambdas in RAV(implicit = yes). Summary: Prior to r351069, lambda classes were traversed or not depending on the {Function, Class, Namespace, TU} DeclContext containing them. If it was a function (common case) they were not traversed. If it was a namespace or TU (top-level lambda) they were traversed as part of that DeclContext traversal. r351069 "fixed" RAV to traverse these as part of the LambdaExpr, which is the right place. But top-level lambdas are now traversed twice. We fix that as blocks and block captures were apparently fixed in the past. Maybe it would be nicer to avoid adding the lambda classes to the DeclContext in the first place, but I can't work out the implications of that. Reviewers: bkramer, klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D56665 llvm-svn: 351075 --- clang/include/clang/AST/RecursiveASTVisitor.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'clang/include') diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h index 96f3d24c6db8..44aba6355758 100644 --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -1368,9 +1368,14 @@ DEF_TRAVERSE_TYPELOC(PipeType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); }) template bool RecursiveASTVisitor::canIgnoreChildDeclWhileTraversingDeclContext( const Decl *Child) { - // BlockDecls and CapturedDecls are traversed through BlockExprs and - // CapturedStmts respectively. - return isa(Child) || isa(Child); + // BlockDecls are traversed through BlockExprs, + // CapturedDecls are traversed through CapturedStmts. + if (isa(Child) || isa(Child)) + return true; + // Lambda classes are traversed through LambdaExprs. + if (const CXXRecordDecl* Cls = dyn_cast(Child)) + return Cls->isLambda(); + return false; } template -- cgit v1.2.3