You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/testassert.cpp
+45Lines changed: 45 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -89,6 +89,51 @@ class TestAssert : public TestFixture {
89
89
"assert(foo() == 3); \n"
90
90
);
91
91
ASSERT_EQUALS("[test.cpp:6]: (warning) Assert statement calls a function which may have desired side effects: 'foo'.\n", errout.str());
92
+
93
+
// Ticket #4937 "false positive: Assert calls a function which may have desired side effects"
94
+
check("struct SquarePack {\n"
95
+
" static bool isRank1Or8( Square sq ) {\n"
96
+
" sq &= 0x38;\n"
97
+
" return sq == 0 || sq == 0x38;\n"
98
+
" }\n"
99
+
"};\n"
100
+
"void foo() {\n"
101
+
" assert( !SquarePack::isRank1Or8(push2) );\n"
102
+
"}\n");
103
+
ASSERT_EQUALS("", errout.str());
104
+
105
+
check("struct SquarePack {\n"
106
+
" static bool isRank1Or8( Square &sq ) {\n"
107
+
" sq &= 0x38;\n"
108
+
" return sq == 0 || sq == 0x38;\n"
109
+
" }\n"
110
+
"};\n"
111
+
"void foo() {\n"
112
+
" assert( !SquarePack::isRank1Or8(push2) );\n"
113
+
"}\n");
114
+
ASSERT_EQUALS("[test.cpp:8]: (warning) Assert statement calls a function which may have desired side effects: 'isRank1Or8'.\n", errout.str());
115
+
116
+
check("struct SquarePack {\n"
117
+
" static bool isRank1Or8( Square *sq ) {\n"
118
+
" *sq &= 0x38;\n"
119
+
" return *sq == 0 || *sq == 0x38;\n"
120
+
" }\n"
121
+
"};\n"
122
+
"void foo() {\n"
123
+
" assert( !SquarePack::isRank1Or8(push2) );\n"
124
+
"}\n");
125
+
ASSERT_EQUALS("[test.cpp:8]: (warning) Assert statement calls a function which may have desired side effects: 'isRank1Or8'.\n", errout.str());
126
+
127
+
check("struct SquarePack {\n"
128
+
" static bool isRank1Or8( Square *sq ) {\n"
129
+
" sq &= 0x38;\n"
130
+
" return sq == 0 || sq == 0x38;\n"
131
+
" }\n"
132
+
"};\n"
133
+
"void foo() {\n"
134
+
" assert( !SquarePack::isRank1Or8(push2) );\n"
135
+
"}\n");
136
+
TODO_ASSERT_EQUALS("", "[test.cpp:8]: (warning) Assert statement calls a function which may have desired side effects: 'isRank1Or8'.\n", errout.str());
0 commit comments