summaryrefslogtreecommitdiff
path: root/test/SemaCXX/compare.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/SemaCXX/compare.cpp')
-rw-r--r--test/SemaCXX/compare.cpp26
1 files changed, 21 insertions, 5 deletions
diff --git a/test/SemaCXX/compare.cpp b/test/SemaCXX/compare.cpp
index 0528b044fb1f..d852180c0663 100644
--- a/test/SemaCXX/compare.cpp
+++ b/test/SemaCXX/compare.cpp
@@ -73,7 +73,7 @@ int test0(long a, unsigned long b) {
((int) a == (unsigned int) B) +
((short) a == (unsigned short) B) +
((signed char) a == (unsigned char) B) +
- (a < (unsigned long) B) + // expected-warning {{comparison of integers of different signs}}
+ (a < (unsigned long) B) + // expected-warning {{comparison of unsigned expression < 0 is always false}}
(a < (unsigned int) B) +
(a < (unsigned short) B) +
(a < (unsigned char) B) +
@@ -81,8 +81,8 @@ int test0(long a, unsigned long b) {
((int) a < B) +
((short) a < B) +
((signed char) a < B) +
- ((long) a < (unsigned long) B) + // expected-warning {{comparison of integers of different signs}}
- ((int) a < (unsigned int) B) + // expected-warning {{comparison of integers of different signs}}
+ ((long) a < (unsigned long) B) + // expected-warning {{comparison of unsigned expression < 0 is always false}}
+ ((int) a < (unsigned int) B) + // expected-warning {{comparison of unsigned expression < 0 is always false}}
((short) a < (unsigned short) B) +
((signed char) a < (unsigned char) B) +
@@ -245,8 +245,8 @@ void test4(short s) {
// unsigned.
const unsigned B = -1;
void (s < B); // expected-warning{{comparison of integers of different signs: 'short' and 'const unsigned int'}}
- void (s > B); // expected-warning{{comparison of integers of different signs: 'short' and 'const unsigned int'}}
- void (s <= B); // expected-warning{{comparison of integers of different signs: 'short' and 'const unsigned int'}}
+ void (s > B); // expected-warning{{comparison 'short' > 4294967295 is always false}}
+ void (s <= B); // expected-warning{{comparison 'short' <= 4294967295 is always true}}
void (s >= B); // expected-warning{{comparison of integers of different signs: 'short' and 'const unsigned int'}}
void (s == B); // expected-warning{{comparison of integers of different signs: 'short' and 'const unsigned int'}}
void (s != B); // expected-warning{{comparison of integers of different signs: 'short' and 'const unsigned int'}}
@@ -423,3 +423,19 @@ namespace templates {
testx<B>();
}
}
+
+namespace tautological_enum {
+ enum E { a, b, c } e;
+
+ // FIXME: We should warn about constructing this out-of-range numeration value.
+ const E invalid = (E)-1;
+ // ... but we should not warn about comparing against it.
+ bool x = e == invalid;
+
+ // We should not warn about relational comparisons for enumerators, even if
+ // they're tautological.
+ bool y = e >= a && e <= b;
+ const E first_in_range = a;
+ const E last_in_range = b;
+ bool z = e >= first_in_range && e <= last_in_range;
+}