[PATCH] D83855: [clang] Fix printing of lambdas with capture expressions
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 15 08:26:11 PDT 2020
kadircet added inline comments.
================
Comment at: clang/lib/AST/StmtPrinter.cpp:2011
+ Expr *Init = D->getInit();
+ if (D->getInitStyle() == VarDecl::CallInit && !isa<ParenListExpr>(Init))
+ OS << "(";
----------------
walrus wrote:
> kadircet wrote:
> > what about having a `Pre` and `Post` print blocks, set to `"(" and ")"` or `" = ` and ""` respectively?
> >
> > that way we could get rid of the second if block below.
> >
> >
> > also i don't follow why blacklisting for parenlistexpr is needed here (i can see that it will end up printing double parens, but so is `ParenExpr`s, and I think both of them shouldn't be showing up as initializer exprs of captured variables), could you elaborate with a comment and a test case?
> I think you're right that skipping `ParenListExpr` is wrong here. I took this part of code from DeclPrinter. The `ParenListExpr`s are skipped when printing variable declarations, but I think it is not applicable when printing lambda expression captures.
>
> Honestly, I didn't get about `Pre` and `Post` blocks. I know it is supported when printing types, but I could not find how to do this for expressions.
i meant something like below, (modulo naming):
```
llvm::StringRef Pre;
llvm::StringRef Post;
if(Style == CallInit) {
Pre = "(";
Post = ")";
}
else if (Style == CInit)
Pre = " = ";
OS << Pre;
PrintExpr(Init):
OS << Post;
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D83855/new/
https://reviews.llvm.org/D83855
More information about the cfe-commits
mailing list