forked from flang-compiler/flang-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ObjC] Add a warning for implicit conversions of a constant non-boole…
…an value to BOOL rdar://51954400 Differential revision: https://reviews.llvm.org/D63912 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@365518 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
Showing
5 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// RUN: %clang_cc1 -Werror=constant-conversion %s -fixit-recompile -fixit-to-temporary -E -o - | FileCheck %s | ||
|
||
typedef signed char BOOL; | ||
|
||
BOOL b; | ||
|
||
int main() { | ||
BOOL b = 2; | ||
// CHECK: BOOL b = 2 ? YES : NO; | ||
|
||
b = b ? 2 : 1; | ||
// CHECK: b = b ? 2 ? YES : NO : 1; | ||
|
||
b = b ? 1 : 2; | ||
// CHECK: b = b ? 1 : 2 ? YES : NO; | ||
|
||
b = b ? 2 : 2; | ||
// CHECK: b = b ? 2 ? YES : NO : 2 ? YES : NO; | ||
|
||
b = 1 + 1; | ||
// CHECK: b = (1 + 1) ? YES : NO; | ||
|
||
b = 1 | 2; | ||
// CHECK: b = (1 | 2) ? YES : NO; | ||
|
||
b = 1 << 1; | ||
// CHECK: b = (1 << 1) ? YES : NO; | ||
} | ||
|
||
@interface BoolProp | ||
@property BOOL b; | ||
@end | ||
|
||
void f(BoolProp *bp) { | ||
bp.b = 43; | ||
// CHECK: bp.b = 43 ? YES : NO; | ||
|
||
[bp setB:43]; | ||
// CHECK: [bp setB:43 ? YES : NO]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// RUN: %clang_cc1 %s -verify -fsyntax-only | ||
|
||
typedef signed char BOOL; | ||
#define YES __objc_yes | ||
#define NO __objc_no | ||
|
||
BOOL B; | ||
|
||
int main() { | ||
B = 0; | ||
B = 1; | ||
B = YES; | ||
B = NO; | ||
|
||
B = -1; // expected-warning{{implicit conversion from constant value -1 to BOOL; the only well defined values for BOOL are YES and NO}} | ||
B = 0 - 1; // expected-warning{{implicit conversion from constant value -1 to BOOL; the only well defined values for BOOL are YES and NO}} | ||
B = YES + YES; // expected-warning {{implicit conversion from constant value 2 to BOOL; the only well defined values for BOOL are YES and NO}} | ||
B = YES | YES; | ||
|
||
B = B ? 2 : 2; // expected-warning 2 {{implicit conversion from constant value 2 to BOOL; the only well defined values for BOOL are YES and NO}} | ||
|
||
BOOL Init = -1; // expected-warning{{implicit conversion from constant value -1 to BOOL; the only well defined values for BOOL are YES and NO}} | ||
BOOL Init2 = B ? 2 : 2; // expected-warning 2 {{implicit conversion from constant value 2 to BOOL; the only well defined values for BOOL are YES and NO}} | ||
|
||
void takesbool(BOOL); | ||
takesbool(43); // expected-warning {{implicit conversion from constant value 43 to BOOL; the only well defined values for BOOL are YES and NO}} | ||
|
||
BOOL OutOfRange = 400; // expected-warning{{implicit conversion from constant value 400 to BOOL; the only well defined values for BOOL are YES and NO}} | ||
} | ||
|
||
@interface BoolProp | ||
@property BOOL b; | ||
@end | ||
|
||
void f(BoolProp *bp) { | ||
bp.b = 43; // expected-warning {{implicit conversion from constant value 43 to BOOL; the only well defined values for BOOL are YES and NO}} | ||
[bp setB:43]; // expected-warning {{implicit conversion from constant value 43 to BOOL; the only well defined values for BOOL are YES and NO}} | ||
} |