[PATCH] D31153: Add the ability to use the children() range API in a const-correct manner

David Blaikie via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 11 09:43:27 PDT 2017


dblaikie added inline comments.


================
Comment at: include/clang/AST/Expr.h:4025
   child_range children() {
+    const_child_range CCR = const_cast<const InitListExpr *>(this)->children();
+    return child_range(cast_away_const(CCR.begin()),
----------------
If this is adding const, can you use a weaker cast? (I guess what would be ideal here would be implicit_cast - if you're interested you could add that - otherwise... yeah, I guess static_cast could do other nasty things, etc, so there's nothing good)


================
Comment at: include/clang/AST/StmtIterator.h:148-150
+inline StmtIterator cast_away_const(const ConstStmtIterator &RHS) {
+  return RHS;
+}
----------------
Maybe I'm missing something - what stops code from doing this conversion implicitly/accidentally all over the place? (I would've expecetd cast_away_const to be a friend or something, to only allow the conversion through this explicit call/operation)


https://reviews.llvm.org/D31153





More information about the cfe-commits mailing list