From ddd84f9b98a83dc41c44f2950180950ded496b7e Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 10 Feb 2022 20:05:14 +0100 Subject: [PATCH] Add tests/TODO for #7950, #9974 (#3818) * Add tests/TODO for #7950, #9974 * Comment --- test/testbufferoverrun.cpp | 7 +++++++ test/testother.cpp | 12 ++++++++++++ test/testsimplifytokens.cpp | 4 ++++ 3 files changed, 23 insertions(+) diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index df16e4c4a..30211b08d 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -4627,6 +4627,13 @@ private: " char *p = arr + 20;\n" "}"); ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'arr+20' is out of bounds.\n", errout.str()); + + check("char(*g())[1];\n" // #7950 + "void f() {\n" + " int a[2];\n" + " int* b = a + sizeof(*g());\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } #define ctu(code) ctu_(code, __FILE__, __LINE__) diff --git a/test/testother.cpp b/test/testother.cpp index 57b488851..80e55792e 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -231,6 +231,7 @@ private: TEST_CASE(doubleMove1); TEST_CASE(doubleMoveMemberInitialization1); TEST_CASE(doubleMoveMemberInitialization2); + TEST_CASE(doubleMoveMemberInitialization3); // #9974 TEST_CASE(moveAndAssign1); TEST_CASE(moveAndAssign2); TEST_CASE(moveAssignMoveAssign); @@ -9069,6 +9070,17 @@ private: ASSERT_EQUALS("[test.cpp:5]: (warning) Access of moved variable 'b'.\n", errout.str()); } + void doubleMoveMemberInitialization3() { // #9974 + check("struct A { int i; };\n" + "struct B { A a1; A a2; };\n" + "B f() {\n" + " A a1 = { 1 };\n" + " A a2 = { 2 };\n" + " return { .a1 = std::move(a1), .a2 = std::move(a2) };\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void moveAndAssign1() { check("A g(A a);\n" "void f() {\n" diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index ac129c49f..632d8d0fe 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -2458,6 +2458,10 @@ private: "sizeof(char[20][3]);\n" "sizeof(char[unknown][3]);"; ASSERT_EQUALS("20 ; 60 ; sizeof ( char [ unknown ] [ 3 ] ) ;", tok(code)); + + code = "char(*Helper())[1];\n" + "sizeof(*Helper());\n"; + TODO_ASSERT_EQUALS("char ( * Helper ( ) ) [ 1 ] ; 1 ;", "char ( * Helper ( ) ) [ 1 ] ; sizeof ( * Helper ( ) ) ;", tok(code)); } void sizeof5() {