Skip to content

Commit ee747ad

Browse files
authored
Move tests created in danmar#6911 (danmar#6913)
1 parent 4cbffa4 commit ee747ad

File tree

2 files changed

+43
-51
lines changed

2 files changed

+43
-51
lines changed

test/testclass.cpp

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ class TestClass : public TestFixture {
8080
TEST_CASE(operatorEqToSelf8); // ticket #2179
8181
TEST_CASE(operatorEqToSelf9); // ticket #2592
8282

83-
TEST_CASE(operatorEqPtrAssign); // ticket #13203
84-
8583
TEST_CASE(memsetOnStruct);
8684
TEST_CASE(memsetVector);
8785
TEST_CASE(memsetOnClass);
@@ -2591,55 +2589,6 @@ class TestClass : public TestFixture {
25912589
ASSERT_EQUALS("", errout_str());
25922590
}
25932591

2594-
#define checkConstructors(code) checkConstructors_(code, __FILE__, __LINE__)
2595-
template<size_t size>
2596-
void checkConstructors_(const char (&code)[size], const char* file, int line) {
2597-
const Settings settings = settingsBuilder().severity(Severity::warning).build();
2598-
2599-
// Tokenize..
2600-
SimpleTokenizer tokenizer(settings, *this);
2601-
ASSERT_LOC(tokenizer.tokenize(code), file, line);
2602-
2603-
// Check..
2604-
CheckClass checkClass(&tokenizer, &settings, this);
2605-
(checkClass.constructors)();
2606-
}
2607-
2608-
void operatorEqPtrAssign() { // ticket #13203
2609-
checkConstructors("struct S {\n"
2610-
" int* m_data;\n"
2611-
" S() : m_data(new int()) {}\n"
2612-
" S& operator=(const S& s) {\n"
2613-
" if (&s != this) {\n"
2614-
" *(m_data) = *(s.m_data);\n"
2615-
" }\n"
2616-
" return *this;\n"
2617-
" }\n"
2618-
"};\n");
2619-
ASSERT_EQUALS("", errout_str());
2620-
2621-
checkConstructors("struct S {\n"
2622-
" int* m_data;\n"
2623-
" S() : m_data(new int()) {}\n"
2624-
" S& operator=(const S& s) {\n"
2625-
" if (&s != this) {\n"
2626-
" (*m_data) = *(s.m_data);\n"
2627-
" }\n"
2628-
" return *this;\n"
2629-
" }\n"
2630-
"};\n");
2631-
ASSERT_EQUALS("", errout_str());
2632-
2633-
checkConstructors("struct S {\n"
2634-
" int* m_data;\n"
2635-
" S() : m_data(new int()) {}\n"
2636-
" S& operator=(const S& s) {\n"
2637-
" return *this;\n"
2638-
" }\n"
2639-
"};\n");
2640-
ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'S::m_data' is not assigned a value in 'S::operator='.\n", errout_str());
2641-
}
2642-
26432592
// Check that base classes have virtual destructors
26442593
#define checkVirtualDestructor(...) checkVirtualDestructor_(__FILE__, __LINE__, __VA_ARGS__)
26452594
template<size_t size>

test/testconstructors.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ class TestConstructors : public TestFixture {
104104
TEST_CASE(initvar_operator_eq6);
105105
TEST_CASE(initvar_operator_eq7);
106106
TEST_CASE(initvar_operator_eq8);
107+
TEST_CASE(initvar_operator_eq9);
108+
TEST_CASE(initvar_operator_eq10);
109+
TEST_CASE(initvar_operator_eq11);
107110
TEST_CASE(initvar_same_classname); // BUG 2208157
108111
TEST_CASE(initvar_chained_assign); // BUG 2270433
109112
TEST_CASE(initvar_2constructors); // BUG 2270353
@@ -997,6 +1000,46 @@ class TestConstructors : public TestFixture {
9971000
"[test.cpp:13]: (warning) Member variable 'D3::d2' is not assigned a value in 'D3::operator='.\n", errout_str());
9981001
}
9991002

1003+
void initvar_operator_eq9() { // ticket #13203
1004+
check("struct S {\n"
1005+
" int* m_data;\n"
1006+
" S() : m_data(new int()) {}\n"
1007+
" S& operator=(const S& s) {\n"
1008+
" if (&s != this) {\n"
1009+
" *(m_data) = *(s.m_data);\n"
1010+
" }\n"
1011+
" return *this;\n"
1012+
" }\n"
1013+
"};\n");
1014+
ASSERT_EQUALS("", errout_str());
1015+
}
1016+
1017+
void initvar_operator_eq10() {
1018+
check("struct S {\n"
1019+
" int* m_data;\n"
1020+
" S() : m_data(new int()) {}\n"
1021+
" S& operator=(const S& s) {\n"
1022+
" if (&s != this) {\n"
1023+
" (*m_data) = *(s.m_data);\n"
1024+
" }\n"
1025+
" return *this;\n"
1026+
" }\n"
1027+
"};\n");
1028+
ASSERT_EQUALS("", errout_str());
1029+
}
1030+
1031+
void initvar_operator_eq11() {
1032+
check("struct S {\n"
1033+
" int* m_data;\n"
1034+
" S() : m_data(new int()) {}\n"
1035+
" S& operator=(const S& s) {\n"
1036+
" return *this;\n"
1037+
" }\n"
1038+
"};\n");
1039+
ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'S::m_data' is not assigned a value in 'S::operator='.\n", errout_str());
1040+
}
1041+
1042+
10001043
void initvar_same_classname() {
10011044
// Bug 2208157 - False positive: Uninitialized variable, same class name
10021045

0 commit comments

Comments
 (0)