One: Compiler: Fix static code analysis reports

Created on 8 May 2020  路  5Comments  路  Source: Samsung/ONE

Need to fix our internal code analysis reports

All 5 comments

611 should land for recent project reports

Lots of problems are like

auto node = dynamic_cast<luci::CircleNode *>(nodes->at(n));
assert(node != nullptr);
if (node->dosomething())
{

where node can be nullptr

We can introduce template method loco::cast<luci::CircleNode *>(nodes->at(n)); that throws when result is nullptr

CC @parjong

Just for suggestion. How about must<T> instead of cast<T> ;-)

This example code shows how to rewrite the above code ;-)

auto node = must<luci::CircleNode>(nodes.at(n));
if (node ->dosomething())
{
  ...
}

If node can be nullptr, I usually prefer to the following pattern:

if (auto node = dynamic_cast...)
{
  node->doSomething()
}

I think this can be close.

Was this page helpful?
0 / 5 - 0 ratings