Skip to content

Commit b72f7a7

Browse files
committed
[clang] Merged diagnostic warn_condition_is_assignment into generic warn_assignment_bool_context
1 parent 303a982 commit b72f7a7

15 files changed

+43
-46
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8474,9 +8474,6 @@ def err_cannot_form_pointer_to_member_of_reference_type : Error<
84748474
def err_incomplete_object_call : Error<
84758475
"incomplete type in call to object of type %0">;
84768476

8477-
def warn_condition_is_assignment : Warning<"using the result of an "
8478-
"assignment as a condition without parentheses">,
8479-
InGroup<Parentheses>;
84808477
def warn_assignment_bool_context : Warning<"using the result of an assignment as a truth value without parentheses">,
84818478
InGroup<Parentheses>;
84828479

clang/lib/Sema/SemaExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20203,7 +20203,7 @@ bool Sema::CheckCallReturnType(QualType ReturnType, SourceLocation Loc,
2020320203
void Sema::DiagnoseAssignmentAsCondition(Expr *E) {
2020420204
SourceLocation Loc;
2020520205

20206-
unsigned diagnostic = diag::warn_condition_is_assignment;
20206+
unsigned diagnostic = diag::warn_assignment_bool_context;
2020720207
bool IsOrAssign = false;
2020820208

2020920209
if (BinaryOperator *Op = dyn_cast<BinaryOperator>(E)) {

clang/test/CodeCompletion/crash-skipped-bodies-template-inst.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ auto make_func() {
66
int x;
77
if (x = 10) {}
88
// Check that body of this function is actually skipped.
9-
// CHECK-NOT: crash-skipped-bodies-template-inst.cpp:7:{{[0-9]+}}: warning: using the result of an assignment as a condition without parentheses
9+
// CHECK-NOT: crash-skipped-bodies-template-inst.cpp:7:{{[0-9]+}}: warning: using the result of an assignment as a truth value without parentheses
1010
return this;
1111
}
1212
};
1313

1414
int x;
1515
if (x = 10) {}
1616
// Check that this function is not skipped.
17-
// CHECK: crash-skipped-bodies-template-inst.cpp:15:9: warning: using the result of an assignment as a condition without parentheses
17+
// CHECK: crash-skipped-bodies-template-inst.cpp:15:9: warning: using the result of an assignment as a truth value without parentheses
1818
return impl();
1919
}
2020

clang/test/CodeCompletion/skip-auto-funcs.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ auto not_skipped() {
77
int x;
88
if (x = 10) {}
99
// Check that this function is not skipped.
10-
// CHECK: 8:9: warning: using the result of an assignment as a condition without parentheses
10+
// CHECK: 8:9: warning: using the result of an assignment as a truth value without parentheses
1111
return 1;
1212
}
1313

@@ -16,7 +16,7 @@ auto lambda_not_skipped = []() {
1616
int x;
1717
if (x = 10) {}
1818
// Check that this function is not skipped.
19-
// CHECK: 17:9: warning: using the result of an assignment as a condition without parentheses
19+
// CHECK: 17:9: warning: using the result of an assignment as a truth value without parentheses
2020
return 1;
2121
}
2222

@@ -25,15 +25,15 @@ auto skipped() -> T {
2525
int x;
2626
if (x = 10) {}
2727
// Check that this function is skipped.
28-
// CHECK-NOT: 26:9: warning: using the result of an assignment as a condition without parentheses
28+
// CHECK-NOT: 26:9: warning: using the result of an assignment as a truth value without parentheses
2929
return 1;
3030
};
3131

3232
auto lambda_skipped = []() -> int {
3333
int x;
3434
if (x = 10) {}
3535
// This could potentially be skipped, but it isn't at the moment.
36-
// CHECK: 34:9: warning: using the result of an assignment as a condition without parentheses
36+
// CHECK: 34:9: warning: using the result of an assignment as a truth value without parentheses
3737
return 1;
3838
};
3939

@@ -42,7 +42,7 @@ decltype(auto)** not_skipped_ptr() {
4242
int x;
4343
if (x = 10) {}
4444
// Check that this function is not skipped.
45-
// CHECK: 43:9: warning: using the result of an assignment as a condition without parentheses
45+
// CHECK: 43:9: warning: using the result of an assignment as a truth value without parentheses
4646
return T();
4747
}
4848

@@ -51,7 +51,7 @@ decltype(auto) not_skipped_decltypeauto() {
5151
int x;
5252
if (x = 10) {}
5353
// Check that this function is not skipped.
54-
// CHECK: 52:9: warning: using the result of an assignment as a condition without parentheses
54+
// CHECK: 52:9: warning: using the result of an assignment as a truth value without parentheses
5555
return 1;
5656
}
5757

clang/test/Misc/warning-flags-enabled.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// We just check a few to make sure it's doing something sensible.
55
//
66
// CHECK: ext_unterminated_char_or_string
7-
// CHECK: warn_condition_is_assignment
7+
// CHECK: warn_assignment_bool_context
88
// CHECK: warn_null_arg
99

1010

clang/test/Modules/diag-pragma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@import diag_pragma;
77

88
int foo(int x) {
9-
if (x = DIAG_PRAGMA_MACRO) // expected-warning {{using the result of an assignment as a condition without parentheses}} \
9+
if (x = DIAG_PRAGMA_MACRO) // expected-warning {{using the result of an assignment as a truth value without parentheses}} \
1010
// expected-note {{place parentheses}} expected-note {{use '=='}}
1111
return 0;
1212
return 1;

clang/test/Modules/diag-pragma.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ int foo(int x) {
4040

4141
void("bar" + x);
4242

43-
if (x = DIAG_PRAGMA_MACRO) // expected-warning {{using the result of an assignment as a condition without parentheses}} \
43+
if (x = DIAG_PRAGMA_MACRO) // expected-warning {{using the result of an assignment as a truth value without parentheses}} \
4444
// expected-note {{place parentheses}} expected-note {{use '=='}}
4545
return 0;
4646
return 1;

clang/test/OpenMP/crash-skipped-bodies-template-inst.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ auto make_func() {
99
;
1010
}
1111
// Check that body of this function is actually skipped.
12-
// CHECK-NOT: crash-skipped-bodies-template-inst.cpp:7:{{[0-9]+}}: warning: using the result of an assignment as a condition without parentheses
12+
// CHECK-NOT: crash-skipped-bodies-template-inst.cpp:7:{{[0-9]+}}: warning: using the result of an assignment as a truth value without parentheses
1313
return this;
1414
}
1515
};
1616

1717
int x;
1818
if (x = 10) {}
1919
// Check that this function is not skipped.
20-
// CHECK: crash-skipped-bodies-template-inst.cpp:18:9: warning: using the result of an assignment as a condition without parentheses
20+
// CHECK: crash-skipped-bodies-template-inst.cpp:18:9: warning: using the result of an assignment as a truth value without parentheses
2121
return impl();
2222
}
2323

clang/test/Sema/parentheses.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Test the various warnings under -Wparentheses
66
void if_assign(void) {
77
int i;
8-
if (i = 4) {} // expected-warning {{assignment as a condition}} \
8+
if (i = 4) {} // expected-warning {{assignment as a truth value}} \
99
// expected-note{{place parentheses around the assignment to silence this warning}} \
1010
// expected-note{{use '==' to turn this assignment into an equality comparison}}
1111
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:7-[[@LINE-3]]:7}:"("
@@ -118,4 +118,4 @@ void conditional_op(int x, int y, _Bool b, void* p) {
118118
}
119119

120120
// RUN: not %clang_cc1 -fsyntax-only -Wparentheses -Werror %s 2>&1 | FileCheck %s -check-prefix=CHECK-FLAG
121-
// CHECK-FLAG: error: using the result of an assignment as a condition without parentheses [-Werror,-Wparentheses]
121+
// CHECK-FLAG: error: using the result of an assignment as a truth value without parentheses [-Werror,-Wparentheses]

clang/test/Sema/warn-assignment-bool-context.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ bool f3(bool x) { return x = 0; }
1414
void test() {
1515
int x;
1616

17-
// This should emit the `warn_condition_is_assignment` warning, since
17+
// This should emit the `warn_assignment_bool_context` warning once, since
1818
// C doesn't do implicit conversion booleans for conditions.
19-
if (x = 0) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \
19+
if (x = 0) {} // expected-warning {{using the result of an assignment as a truth value without parentheses}} \
2020
// expected-note{{place parentheses around the assignment to silence this warning}}\
2121
// expected-note{{use '==' to turn this assignment into an equality comparison}}
22-
if (x = 4 && x){} // expected-warning {{using the result of an assignment as a condition without parentheses}} \
22+
if (x = 4 && x){} // expected-warning {{using the result of an assignment as a truth value without parentheses}} \
2323
// expected-note{{place parentheses around the assignment to silence this warning}}\
2424
// expected-note{{use '==' to turn this assignment into an equality comparison}}
2525

0 commit comments

Comments
 (0)