summaryrefslogtreecommitdiff
path: root/test/Sema
diff options
context:
space:
mode:
authorRoman Divacky <rdivacky@FreeBSD.org>2009-11-05 17:18:09 +0000
committerRoman Divacky <rdivacky@FreeBSD.org>2009-11-05 17:18:09 +0000
commit8f57cb0305232cb53fff00ef151ca716766f3437 (patch)
tree8b316eca843681b024034db1125707173b9adb4a /test/Sema
parent51fb8b013e7734b795139f49d3b1f77c539be20a (diff)
Notes
Diffstat (limited to 'test/Sema')
-rw-r--r--test/Sema/compare.c20
-rw-r--r--test/Sema/conditional-expr.c19
2 files changed, 39 insertions, 0 deletions
diff --git a/test/Sema/compare.c b/test/Sema/compare.c
index 87131bb62183a..9cbbfba935bd0 100644
--- a/test/Sema/compare.c
+++ b/test/Sema/compare.c
@@ -7,6 +7,26 @@ int test(char *C) { // nothing here should warn.
return C != 1; // expected-warning {{comparison between pointer and integer ('char *' and 'int')}}
}
+int ints(long a, unsigned long b) {
+ return (a == b) + // expected-warning {{comparison of integers of different signs}}
+ ((int)a == b) + // expected-warning {{comparison of integers of different signs}}
+ ((short)a == b) + // expected-warning {{comparison of integers of different signs}}
+ (a == (unsigned int) b) + // expected-warning {{comparison of integers of different signs}}
+ (a == (unsigned short) b); // expected-warning {{comparison of integers of different signs}}
+
+ enum Enum {B};
+ return (a == B) +
+ ((int)a == B) +
+ ((short)a == B) +
+ (a == (unsigned int) B) + // expected-warning {{comparison of integers of different signs}}
+ (a == (unsigned short) B); // expected-warning {{comparison of integers of different signs}}
+
+ // Should be able to prove all of these are non-negative.
+ return (b == (long) B) +
+ (b == (int) B) +
+ (b == (short) B);
+}
+
int equal(char *a, const char *b) {
return a == b;
}
diff --git a/test/Sema/conditional-expr.c b/test/Sema/conditional-expr.c
index 1f0a9deb5e47d..3bfeae5d4c5eb 100644
--- a/test/Sema/conditional-expr.c
+++ b/test/Sema/conditional-expr.c
@@ -34,6 +34,25 @@ void foo() {
typedef void *asdf;
*(0 ? (asdf) 0 : &x) = 10;
+
+ unsigned long test0 = 5;
+ test0 = test0 ? (long) test0 : test0; // expected-warning {{operands of ? are integers of different signs}}
+ test0 = test0 ? (int) test0 : test0; // expected-warning {{operands of ? are integers of different signs}}
+ test0 = test0 ? (short) test0 : test0; // expected-warning {{operands of ? are integers of different signs}}
+ test0 = test0 ? test0 : (long) test0; // expected-warning {{operands of ? are integers of different signs}}
+ test0 = test0 ? test0 : (int) test0; // expected-warning {{operands of ? are integers of different signs}}
+ test0 = test0 ? test0 : (short) test0; // expected-warning {{operands of ? are integers of different signs}}
+ test0 = test0 ? test0 : (long) 10;
+ test0 = test0 ? test0 : (int) 10;
+ test0 = test0 ? test0 : (short) 10;
+ test0 = test0 ? (long) 10 : test0;
+ test0 = test0 ? (int) 10 : test0;
+ test0 = test0 ? (short) 10 : test0;
+
+ enum Enum { EVal };
+ test0 = test0 ? EVal : test0;
+ test0 = test0 ? EVal : (int) test0; // okay: EVal is an int
+ test0 = test0 ? (unsigned) EVal : (int) test0; // expected-warning {{operands of ? are integers of different signs}}
}
int Postgresql() {