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/testbool.cpp
+20Lines changed: 20 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -922,10 +922,30 @@ class TestBool : public TestFixture {
922
922
"}");
923
923
ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout.str());
924
924
925
+
check("void f(char *p) {\n"
926
+
" do {} while (p+1);\n"
927
+
"}");
928
+
ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout.str());
929
+
930
+
check("void f(char *p) {\n"
931
+
" while (p-1) {}\n"
932
+
"}");
933
+
ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout.str());
934
+
935
+
check("void f(char *p) {\n"
936
+
" for (int i = 0; p+1; i++) {}\n"
937
+
"}");
938
+
ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout.str());
939
+
925
940
check("void f(char *p) {\n"
926
941
" if (p && p+1){}\n"
927
942
"}");
928
943
ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout.str());
944
+
945
+
check("void f(char *p) {\n"
946
+
" if (p+2 || p) {}\n"
947
+
"}");
948
+
ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout.str());
0 commit comments