<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class=""><div dir="auto" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><div dir="auto" class=""><br class=""></div><div dir="auto" class=""><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div style="word-wrap: break-word; line-break: after-white-space;" class=""><div class="">Stmt {</div><div class=""><span style="white-space: pre-wrap;" class="">     </span>…</div><div class=""><span style="white-space: pre-wrap;" class="">      </span>T *getAs() {</div><div class=""><span style="white-space: pre-wrap;" class="">             </span>if (isa<T>(this))</div><div class=""><span style="white-space: pre-wrap;" class="">                  </span>return cast<T>(this);</div><div class=""><span style="white-space: pre-wrap;" class="">              </span>if (this->isImplicit() || isa<ParenExpr>(this)) {</div><div class=""><span style="white-space: pre-wrap;" class="">                       </span>assert(children.size() == 1 && "Expected implicit nodes to have exactly one child");</div><div class=""><span style="white-space: pre-wrap;" class="">                   </span>return (*children.begin())->getAs<T>();</div><div class=""><span style="white-space: pre-wrap;" class="">         </span>}</div><div class=""><span style="white-space: pre-wrap;" class="">                </span>return nullptr;</div><div class=""><span style="white-space: pre-wrap;" class="">  </span>}</div></div></blockquote></div></div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">Note that the analogy to Type::getAs has already broken down here; getAs always returns a type with the same semantics but a possibly different meaning, whereas this can return an expression with different semantics by skipping implicit nodes.</div><div dir="auto" class=""><br class=""></div></div></div></blockquote></div><br class=""><div class=""><div class="">This, I believe, gets to the heart of the issue Stephen has raised.  In</div><div class=""><br class=""></div><div class="">struct B { B(int); };</div><div class="">B f() { return 42; }</div><div class=""><br class=""></div><div class="">is it ever valid for a user to treat the 42 as an IntegerLiteral, instead of an ExprWCleanups?  </div><div class=""><br class=""></div><div class="">What is interesting about the analogy between the proposed Stmt::getAs<T>() and the existing Type::getAs<T>() is that, considering only their effect on syntax and semantics, they are precisely the opposite (disregarding the extra handling of ParenExpr, which probably should be removed): whereas each desugaring performed in Type::getAs<T> peels back a layer of meaningless syntax to get ever closer to the underlying semantics, Stmt::getAs<T> would peel back layers of invisible semantics to get ever closer to the underlying syntax.</div><div class=""><br class=""></div><div class="">So it might be confusing.</div><div class=""><br class=""></div><div class="">But in another sense, the analogy holds: in both cases, getAs<T> retrieves only the *essential information* about the node: the information without which the semantics could not be reconstructed.  In the case of types, this is the fully de-aliased, de-sugared type.  In the case of Stmts (or really, just Exprs), this is the originally written statement.</div><div class=""><br class=""></div><div class="">So, there are two possible ways the user might interpret a universal getAs, such that it would either confuse them or help them.  I am satisfied the case has been made, will defer to you and others with greater experience and wisdom to reflect on it and decide it.</div><div class=""><br class=""></div><div class="">Thanks for engaging this issue, and Stephen thanks again for raising this important issue,</div><div class=""><br class=""></div><div class="">Dave</div></div></body></html>