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

Method isReturnScopeTest

test/testastutils.cpp:154–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152 }
153
154 void isReturnScopeTest() {
155 ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { return; } }", -2));
156 ASSERT_EQUALS(true, isReturnScope("int f() { if (a) { return {}; } }", -2)); // #8891
157 ASSERT_EQUALS(true, isReturnScope("std::string f() { if (a) { return std::string{}; } }", -2)); // #8891
158 ASSERT_EQUALS(true, isReturnScope("std::string f() { if (a) { return std::string{\"\"}; } }", -2)); // #8891
159 ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { return (ab){0}; } }", -2)); // #7103
160 ASSERT_EQUALS(false, isReturnScope("void f() { if (a) { return (ab){0}; } }", -4)); // #7103
161 ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { {throw new string(x);}; } }", -4)); // #7144
162 ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { {throw new string(x);}; } }", -2)); // #7144
163 ASSERT_EQUALS(false, isReturnScope("void f() { [=]() { return data; }; }", -1));
164 ASSERT_EQUALS(true, isReturnScope("auto f() { return [=]() { return data; }; }", -1));
165 ASSERT_EQUALS(true, isReturnScope("auto f() { return [=]() { return data; }(); }", -1));
166 ASSERT_EQUALS(false, isReturnScope("auto f() { [=]() { return data; }(); }", -1));
167
168 ASSERT_EQUALS(true, isReturnScope("void negativeTokenOffset() { return; }", -1));
169 ASSERT_EQUALS(false, isReturnScope("void zeroTokenOffset() { return; }", 0));
170 ASSERT_EQUALS(true, isReturnScope("void positiveTokenOffset() { return; }", 7));
171 }
172
173#define isSameExpression(...) isSameExpression_(__FILE__, __LINE__, __VA_ARGS__)
174 template<size_t size>

Callers

nothing calls this directly

Calls 1

isReturnScopeFunction · 0.85

Tested by

no test coverage detected