From c878285a4290c037c3fd453ef44b1dbfaf684a7f Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sat, 30 Jul 2022 16:15:32 +0200 Subject: [PATCH] Add tests for #5804, #8958, #9002, #10031 (#4326) --- test/testfunctions.cpp | 10 ++++++++++ test/teststl.cpp | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index dbe03e526..0338243e7 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -1830,6 +1830,16 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + check("void f() { throw(1); }\n"); // #8958 + ASSERT_EQUALS("", errout.str()); + + check("class C {\n" // #9002 + "public:\n" + " static int f() { return 1; }\n" + "};\n" + "void g() { C::f(); }\n"); + ASSERT_EQUALS("", errout.str()); + settings.severity = severity_old; settings.checkLibrary = false; } diff --git a/test/teststl.cpp b/test/teststl.cpp index 12b91143f..d7ea7f62f 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -896,6 +896,11 @@ private: " s[x*s.size()] = 1;\n" "}"); ASSERT_EQUALS("test.cpp:2:error:Out of bounds access of s, index 'x*s.size()' is out of bounds.\n", errout.str()); + + checkNormal("bool f(std::string_view& sv) {\n" // #10031 + " return sv[sv.size()] == '\\0';\n" + "}\n"); + ASSERT_EQUALS("test.cpp:2:error:Out of bounds access of sv, index 'sv.size()' is out of bounds.\n", errout.str()); } void outOfBoundsIterator() { check("int f() {\n" @@ -1575,6 +1580,17 @@ private: ASSERT_EQUALS( "[test.cpp:6] -> [test.cpp:6]: (error) Same iterator is used with containers 'g()' that are temporaries or defined in different scopes.\n", errout.str()); + + check("std::set f() {\n" // #5804 + " std::set s;\n" + " return s;\n" + "}\n" + "void g() {\n" + " for (std::set::iterator it = f().begin(); it != f().end(); ++it) {}\n" + "}\n"); + ASSERT_EQUALS( + "[test.cpp:6] -> [test.cpp:6]: (error) Same iterator is used with containers 'f()' that are temporaries or defined in different scopes.\n", + errout.str()); } void iterator20() {