diff --git a/lib/checkother.cpp b/lib/checkother.cpp index c1318ac05..d12a802fb 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -499,6 +499,9 @@ void CheckOther::warningOldStylePointerCast() if (tok->strAt(1) == "const") tok = tok->next(); + if (tok->strAt(4) == "0") // Casting nullpointers is safe + continue; + // Is "type" a class? if (_tokenizer->getSymbolDatabase()->isClassOrStruct(tok->strAt(1))) cstyleCastError(tok); diff --git a/test/testother.cpp b/test/testother.cpp index a64d1273d..c37b18f99 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1468,6 +1468,12 @@ private: "};"); ASSERT_EQUALS("[test.cpp:3]: (style) C-style pointer casting\n", errout.str()); + checkOldStylePointerCast("class SomeType;\n" + "class X : public Base {\n" + " X() : Base((SomeType*)0) {}\n" + "};"); + ASSERT_EQUALS("", errout.str()); + // #5560 checkOldStylePointerCast("class C;\n" "\n"