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

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 11 10:27:23 PDT 2017


aaron.ballman 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()),
----------------
dblaikie wrote:
> 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)
I'm not certain what you mean. This is adding the const qualifier so that we call the proper overload. I'm not certain of what a weaker cast would be.


================
Comment at: include/clang/AST/StmtIterator.h:148-150
+inline StmtIterator cast_away_const(const ConstStmtIterator &RHS) {
+  return RHS;
+}
----------------
dblaikie wrote:
> 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)
Good catch, I've corrected this.


https://reviews.llvm.org/D31153





More information about the cfe-commits mailing list