@@ -142,6 +142,7 @@ class TestValueFlow : public TestFixture {
142142 TEST_CASE (valueFlowIdempotent);
143143 TEST_CASE (valueFlowUnsigned);
144144 TEST_CASE (valueFlowMod);
145+ TEST_CASE (valueFlowNotNull);
145146 TEST_CASE (valueFlowSymbolic);
146147 TEST_CASE (valueFlowSmartPointer);
147148 }
@@ -6197,6 +6198,43 @@ class TestValueFlow : public TestFixture {
61976198 ASSERT_EQUALS (false , testValueOfXImpossible (code, 3U , 1 ));
61986199 }
61996200
6201+ void valueFlowNotNull ()
6202+ {
6203+ const char * code;
6204+
6205+ code = " int f(const std::string &str) {\n "
6206+ " int x = str.c_str();\n "
6207+ " return x;\n "
6208+ " }\n " ;
6209+ ASSERT_EQUALS (true , testValueOfXImpossible (code, 3U , 0 ));
6210+
6211+ code = " int f(const std::string_view &str) {\n "
6212+ " int x = str.c_str();\n "
6213+ " return x;\n "
6214+ " }\n " ;
6215+ ASSERT_EQUALS (false , testValueOfXImpossible (code, 3U , 0 ));
6216+
6217+ code = " auto f() {\n "
6218+ " std::shared_ptr<int> x = std::make_shared<int>(1);\n "
6219+ " return x;\n "
6220+ " }\n " ;
6221+ ASSERT_EQUALS (true , testValueOfXImpossible (code, 3U , 0 ));
6222+
6223+ code = " auto f() {\n "
6224+ " std::unique_ptr<int> x = std::make_unique<int>(1);\n "
6225+ " return x;\n "
6226+ " }\n " ;
6227+ ASSERT_EQUALS (true , testValueOfXImpossible (code, 3U , 0 ));
6228+
6229+ code = " struct A {\n "
6230+ " A* f() {\n "
6231+ " A* x = this;\n "
6232+ " return x;\n "
6233+ " }\n "
6234+ " };\n " ;
6235+ ASSERT_EQUALS (true , testValueOfXImpossible (code, 4U , 0 ));
6236+ }
6237+
62006238 void valueFlowSymbolic () {
62016239 const char * code;
62026240
0 commit comments