Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field: remove uncallable conversion operator for Array and Table #294

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions include/amqpcpp/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

/**
Expand Down
19 changes: 0 additions & 19 deletions include/amqpcpp/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

/**
Expand Down
14 changes: 12 additions & 2 deletions src/field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const Array*>(this)) {
return *dcp;
}

// otherwise reference an empty Array
return empty;
}

Expand All @@ -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<const Table*>(this)) {
return *dcp;
}

// otherwise reference an empty Table
return empty;
}

Expand Down