MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / valueFlowFunctionReturn

Method valueFlowFunctionReturn

test/testvalueflow.cpp:5116–5304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5114 }
5115
5116 void valueFlowFunctionReturn() {
5117 const char *code;
5118
5119 code = "int f1(int x) {\n"
5120 " return x+1;\n"
5121 "}\n"
5122 "void f2() {\n"
5123 " x = 10 - f1(2);\n"
5124 "}";
5125 ASSERT_EQUALS(7, valueOfTok(code, "-").intvalue);
5126 ASSERT_EQUALS(true, valueOfTok(code, "-").isKnown());
5127
5128 code = "int add(int x, int y) {\n"
5129 " return x+y;\n"
5130 "}\n"
5131 "void f2() {\n"
5132 " x = 2 * add(10+1,4);\n"
5133 "}";
5134 ASSERT_EQUALS(30, valueOfTok(code, "*").intvalue);
5135 ASSERT_EQUALS(true, valueOfTok(code, "*").isKnown());
5136
5137 code = "int one() { return 1; }\n"
5138 "void f() { x = 2 * one(); }";
5139 ASSERT_EQUALS(2, valueOfTok(code, "*").intvalue);
5140 ASSERT_EQUALS(true, valueOfTok(code, "*").isKnown());
5141
5142 code = "int add(int x, int y) {\n"
5143 " return x+y;\n"
5144 "}\n"
5145 "void f2() {\n"
5146 " x = 2 * add(1,add(2,3));\n"
5147 "}";
5148 ASSERT_EQUALS(12, valueOfTok(code, "*").intvalue);
5149 ASSERT_EQUALS(true, valueOfTok(code, "*").isKnown());
5150
5151 code = "int f(int i, X x) {\n"
5152 " if (i)\n"
5153 " return g(std::move(x));\n"
5154 " g(x);\n"
5155 " return 0;\n"
5156 "}";
5157 ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::MoveKind::MovedVariable));
5158
5159 code = "class A\n"
5160 "{\n"
5161 " int f1(int x) {\n"
5162 " return x+1;\n"
5163 " }\n"
5164 " void f2() {\n"
5165 " x = 10 - f1(2);\n"
5166 " }\n"
5167 "};";
5168 ASSERT_EQUALS(7, valueOfTok(code, "-").intvalue);
5169 ASSERT_EQUALS(true, valueOfTok(code, "-").isKnown());
5170
5171 code = "class A\n"
5172 "{\n"
5173 " virtual int f1(int x) {\n"

Callers

nothing calls this directly

Calls 1

isKnownMethod · 0.80

Tested by

no test coverage detected