diff --git a/include/amqpcpp/array.h b/include/amqpcpp/array.h index 7a3c3884..0ae9246c 100644 --- a/include/amqpcpp/array.h +++ b/include/amqpcpp/array.h @@ -218,25 +218,6 @@ class Array : public Field // 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/amqpcpp/table.h b/include/amqpcpp/table.h index edc1e5fd..aaec4123 100644 --- a/include/amqpcpp/table.h +++ b/include/amqpcpp/table.h @@ -252,25 +252,6 @@ class Table : public Field // 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; - } }; /** diff --git a/src/field.cpp b/src/field.cpp index 2655bb22..eb0acc94 100644 --- a/src/field.cpp +++ b/src/field.cpp @@ -67,7 +67,12 @@ Field::operator const Array& () const // static empty array static Array empty; - // return it + // if this is an Array then return it + if (auto dcp = dynamic_cast(this)) { + return *dcp; + } + + // otherwise reference an empty Array return empty; } @@ -80,7 +85,12 @@ Field::operator const Table& () const // static empty table static Table empty; - // return it + // if this is a Table then return it + if (auto dcp = dynamic_cast(this)) { + return *dcp; + } + + // otherwise reference an empty Table return empty; }