From afb04a8f30897e945c975bbe12a8c648e99e2b71 Mon Sep 17 00:00:00 2001 From: Martijn Otto Date: Mon, 5 Sep 2016 10:11:31 +0200 Subject: [PATCH] Re-introduced the casting operators with a note explaining why we need this. --- include/array.h | 19 +++++++++++++++++++ include/table.h | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/array.h b/include/array.h index 0ae9246..7a3c388 100644 --- a/include/array.h +++ b/include/array.h @@ -218,6 +218,25 @@ public: // postfix stream << ")"; } + + /** + * Cast to array. + * + * @note: This function may look silly and unnecessary. We are, after all, already + * an array. The whole reason we still have this function is that it is virtual + * and if we do not declare a cast to array on a pointer to base (i.e. Field) + * will return an empty field instead of the expected array. + * + * Yes, clang gets this wrong and gives incorrect warnings here. See + * https://llvm.org/bugs/show_bug.cgi?id=28263 for more information + * + * @return Ourselves + */ + virtual operator const Array& () const override + { + // this already is an array, so no cast is necessary + return *this; + } }; /** diff --git a/include/table.h b/include/table.h index 30df4d5..c4d158c 100644 --- a/include/table.h +++ b/include/table.h @@ -242,6 +242,25 @@ public: // postfix stream << ")"; } + + /** + * Cast to table. + * + * @note: This function may look silly and unnecessary. We are, after all, already + * a table. The whole reason we still have this function is that it is virtual + * and if we do not declare a cast to table on a pointer to base (i.e. Field) + * will return an empty field instead of the expected table. + * + * Yes, clang gets this wrong and gives incorrect warnings here. See + * https://llvm.org/bugs/show_bug.cgi?id=28263 for more information + * + * @return Ourselves + */ + virtual operator const Table& () const override + { + // this already is a table, so no cast is necessary + return *this; + } }; /**