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

Method valueFlowLifetime

test/testvalueflow.cpp:786–911  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

784 }
785
786 void valueFlowLifetime() {
787 std::vector<std::string> lifetimes;
788
789 {
790 const char code[] = "void f() {\n"
791 " int a = 1;\n"
792 " auto x = [&]() { return a + 1; };\n"
793 " auto b = x;\n"
794 "}\n";
795 ASSERT_EQUALS(true, testLifetimeOfX(code, 4, "a + 1"));
796 }
797
798 {
799 const char code[] = "void f() {\n"
800 " int a = 1;\n"
801 " auto x = [=]() { return a + 1; };\n"
802 " auto b = x;\n"
803 "}\n";
804 ASSERT_EQUALS(false, testLifetimeOfX(code, 4, "a ;"));
805 }
806
807 {
808 const char code[] = "void f(int v) {\n"
809 " int a = v;\n"
810 " int * p = &a;\n"
811 " auto x = [=]() { return p + 1; };\n"
812 " auto b = x;\n"
813 "}\n";
814 ASSERT_EQUALS(true, testLifetimeOfX(code, 5, "a ;"));
815 }
816
817 {
818 const char code[] = "void f() {\n"
819 " std::vector<int> v;\n"
820 " auto x = v.begin();\n"
821 " auto it = x;\n"
822 "}\n";
823 ASSERT_EQUALS(true, testLifetimeOfX(code, 4, "v . begin"));
824 }
825
826 {
827 const char code[] = "void f() {\n"
828 " std::vector<int> v;\n"
829 " auto x = v.begin() + 1;\n"
830 " auto it = x;\n"
831 "}\n";
832 ASSERT_EQUALS(true, testLifetimeOfX(code, 4, "v . begin"));
833 }
834
835 {
836 const char code[] = "int* f() {\n"
837 " std::vector<int> v;\n"
838 " int * x = v.data();\n"
839 " return x;\n"
840 "}\n";
841 ASSERT_EQUALS(true, testLifetimeOfX(code, 4, "v . data"));
842 }
843

Callers

nothing calls this directly

Calls 3

frontMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected