[clang-tidy] using dynamic_cast for derived classes

Found with cppcoreguidelines-pro-type-cstyle-cast

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev 2019-09-27 21:00:49 -07:00 committed by Paul Beckingham
parent 51870dff34
commit a02754159c
2 changed files with 15 additions and 15 deletions

View file

@ -432,13 +432,13 @@ void Hooks::assertValidJSON (
throw 0;
}
if (((json::object*)root)->_data.find ("description") == ((json::object*)root)->_data.end ())
if ((dynamic_cast<json::object*>(root))->_data.find ("description") == (dynamic_cast<json::object*>(root))->_data.end ())
{
Context::getContext ().error (format (STRING_HOOK_ERROR_NODESC, Path (script).name ()));
throw 0;
}
if (((json::object*)root)->_data.find ("uuid") == ((json::object*)root)->_data.end ())
if ((dynamic_cast<json::object*>(root))->_data.find ("uuid") == (dynamic_cast<json::object*>(root))->_data.end ())
{
Context::getContext ().error (format (STRING_HOOK_ERROR_NOUUID, Path (script).name ()));
throw 0;
@ -486,7 +486,7 @@ void Hooks::assertSameTask (
for (auto& i : input)
{
auto* root_obj = (json::object*)json::parse (i);
auto* root_obj = dynamic_cast<json::object*>(json::parse (i));
// If there is no UUID at all.
auto u = root_obj->_data.find ("uuid");
@ -497,7 +497,7 @@ void Hooks::assertSameTask (
throw 0;
}
auto* up = (json::string*) u->second;
auto* up = dynamic_cast<json::string*>( u->second);
auto text = up->dump ();
Lexer::dequote (text);
std::string json_uuid = json::decode (text);

View file

@ -637,7 +637,7 @@ void Task::parseJSON (const std::string& line)
json::value* root = json::parse (line);
if (root &&
root->type () == json::j_object)
parseJSON ((json::object*) root);
parseJSON (dynamic_cast<json::object*>( root));
delete root;
}
@ -681,10 +681,10 @@ void Task::parseJSON (const json::object* root_obj)
// Tags are an array of JSON strings.
else if (i.first == "tags" && i.second->type() == json::j_array)
{
auto* tags = (json::array*)i.second;
auto* tags = dynamic_cast<json::array*>(i.second);
for (auto& t : tags->_data)
{
auto* tag = (json::string*)t;
auto* tag = dynamic_cast<json::string*>(t);
addTag (tag->_data);
}
}
@ -695,7 +695,7 @@ void Task::parseJSON (const json::object* root_obj)
// removed in a later release.
else if (i.first == "tags" && i.second->type() == json::j_string)
{
auto* tag = (json::string*)i.second;
auto* tag = dynamic_cast<json::string*>(i.second);
addTag (tag->_data);
}
@ -704,10 +704,10 @@ void Task::parseJSON (const json::object* root_obj)
// See other 2016-02-21 comments for details.
else if (i.first == "depends" && i.second->type() == json::j_array)
{
auto* deps = (json::array*)i.second;
auto* deps = dynamic_cast<json::array*>(i.second);
for (auto& t : deps->_data)
{
auto* dep = (json::string*)t;
auto* dep = dynamic_cast<json::string*>(t);
addDependency (dep->_data);
}
}
@ -716,7 +716,7 @@ void Task::parseJSON (const json::object* root_obj)
// 2016-02-21: Deprecated - see other 2016-02-21 comments for details.
else if (i.first == "depends" && i.second->type() == json::j_string)
{
auto* deps = (json::string*)i.second;
auto* deps = dynamic_cast<json::string*>(i.second);
auto uuids = split (deps->_data, ',');
for (const auto& uuid : uuids)
@ -749,12 +749,12 @@ void Task::parseJSON (const json::object* root_obj)
{
std::map <std::string, std::string> annos;
auto* atts = (json::array*)i.second;
auto* atts = dynamic_cast<json::array*>(i.second);
for (auto& annotations : atts->_data)
{
auto* annotation = (json::object*)annotations;
json::string* when = (json::string*)annotation->_data["entry"];
json::string* what = (json::string*)annotation->_data["description"];
auto* annotation = dynamic_cast<json::object*>(annotations);
json::string* when = dynamic_cast<json::string*>(annotation->_data["entry"]);
json::string* what = dynamic_cast<json::string*>(annotation->_data["description"]);
if (! when)
throw format ("Annotation is missing an entry date: {1}", root_obj-> dump ());