clio icon indicating copy to clipboard operation
clio copied to clipboard

Make clang-tidy to fail if there is no check after dynamic_cast

Open kuznetsss opened this issue 1 year ago • 1 comments

Currently there are places (mostly in tests) with code like:

auto ptr = dynamic_cast<Foo*>(mockFoo);
EXPECT_EQ(ptr->bar(), expected_value);

and clang-tidy is fine with it. We should force clang-tidy to fail on such places to force to check pointer after dynamic_cast.

kuznetsss avatar Oct 05 '23 15:10 kuznetsss

Tried to use clang-analyzer-core and clang-analyzer-cplusplus (in particular core.NullDereference). Unfortunately it does not seem to catch the cases we want even with this option disabled as suggested in the above link:

CheckOptions:
  core.NullDereference:SuppressAddressSpaces: false

godexsoft avatar Oct 06 '23 16:10 godexsoft