Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f7e2e4d

Browse files
authored
[NFC] [FlowSensitive] [StatusOr] Add test reassigning variable in loop
Reviewers: jvoung Reviewed By: jvoung Pull Request: #180091
1 parent 839676b commit f7e2e4d

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

clang/unittests/Analysis/FlowSensitive/UncheckedStatusOrAccessModelTestFixture.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,55 @@ TEST_P(UncheckedStatusOrAccessModelTest, While_NestedIfWithBinaryCondition) {
11141114
)cc");
11151115
}
11161116

1117+
TEST_P(UncheckedStatusOrAccessModelTest, While_ReassignValueInLoop) {
1118+
ExpectDiagnosticsFor(R"cc(
1119+
#include "unchecked_statusor_access_test_defs.h"
1120+
1121+
void target() {
1122+
STATUSOR_INT sor = 3;
1123+
while (Make<bool>()) sor.value();
1124+
}
1125+
)cc");
1126+
ExpectDiagnosticsFor(R"cc(
1127+
#include "unchecked_statusor_access_test_defs.h"
1128+
1129+
void target() {
1130+
STATUSOR_INT sor = 3;
1131+
while (Make<bool>()) {
1132+
sor.value(); // [[unsafe]]
1133+
1134+
sor = Make<STATUSOR_INT>();
1135+
}
1136+
}
1137+
)cc");
1138+
ExpectDiagnosticsFor(R"cc(
1139+
#include "unchecked_statusor_access_test_defs.h"
1140+
1141+
void target() {
1142+
STATUSOR_INT sor = 3;
1143+
while (Make<bool>()) {
1144+
sor.value();
1145+
1146+
sor = Make<STATUSOR_INT>();
1147+
if (!sor.ok()) return;
1148+
}
1149+
}
1150+
)cc");
1151+
ExpectDiagnosticsFor(R"cc(
1152+
#include "unchecked_statusor_access_test_defs.h"
1153+
1154+
void target() {
1155+
STATUSOR_INT sor = 3;
1156+
while (Make<bool>()) {
1157+
sor.value(); // [[unsafe]]
1158+
1159+
sor = Make<STATUSOR_INT>();
1160+
if (!sor.ok()) continue;
1161+
}
1162+
}
1163+
)cc");
1164+
}
1165+
11171166
TEST_P(UncheckedStatusOrAccessModelTest, BuiltinExpect) {
11181167
ExpectDiagnosticsFor(
11191168
R"cc(

0 commit comments

Comments
 (0)