[PATCH] D76196: [ASTMatchers] Extend hasReturnValue to GNU StmtExpr

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 16 07:00:18 PDT 2020


njames93 added a comment.

In D76196#1924393 <https://reviews.llvm.org/D76196#1924393>, @aaron.ballman wrote:

> I'm still not understanding your use case, so it's a bit hard for me to tell whether this approach is good or not. Do you have a situation where you cannot match on the expression itself, you also have to know its position? I'm asking because we don't currently have support for querying positional statements (for instance, you cannot ask what the final statement in a `CompoundStmt`) and statement expressions are a bit strange. For instance, what would the final "expression" be in this legal-but-bizarre statement expression: `({int j = 12; j; int x;});`?


It would be the `int x;` but not matchable as its not an expression. The way `StmtExpr` works is it evaluates each `Stmt` in order and returns the result of the last `Stmt`, if it is an expression. otherwise it basically returns `void`. Possible use cases are if you want to match on say an if condition, but the condition is inside a `StmtExpr`. I feel like there could be a better way to get this behaviour but I'm not exactly sure what it is


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76196/new/

https://reviews.llvm.org/D76196





More information about the cfe-commits mailing list