summaryrefslogtreecommitdiff
path: root/clang/test/SemaCXX/expressions.cpp
diff options
context:
space:
mode:
authorZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-09-24 09:58:17 +1000
committerZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-09-24 09:58:17 +1000
commit222e2a7620e6520ffaf4fc4e69d79c18da31542e (patch)
tree7bfbc05bfa3b41c8f9d2e56d53a0bc3e310df239 /clang/test/SemaCXX/expressions.cpp
parent3d206f03985b50beacae843d880bccdc91a9f424 (diff)
Add the clang library to the repo (with some of my changes, too).
Diffstat (limited to 'clang/test/SemaCXX/expressions.cpp')
-rw-r--r--clang/test/SemaCXX/expressions.cpp120
1 files changed, 120 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/expressions.cpp b/clang/test/SemaCXX/expressions.cpp
new file mode 100644
index 0000000..355833e
--- /dev/null
+++ b/clang/test/SemaCXX/expressions.cpp
@@ -0,0 +1,120 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void choice(int);
+int choice(bool);
+
+void test() {
+ // Result of ! must be type bool.
+ int i = choice(!1);
+}
+
+// rdar://8018252
+void f0() {
+ extern void f0_1(int*);
+ register int x;
+ f0_1(&x);
+}
+
+namespace test1 {
+ template <class T> void bar(T &x) { T::fail(); }
+ template <class T> void bar(volatile T &x) {}
+
+ void test_ints() {
+ volatile int x;
+ bar(x = 5);
+ bar(x += 5);
+ }
+
+ enum E { E_zero };
+ void test_enums() {
+ volatile E x;
+ bar(x = E_zero);
+ bar(x += E_zero); // expected-error {{incompatible type}}
+ }
+}
+
+int test2(int x) {
+ return x && 4; // expected-warning {{use of logical '&&' with constant operand}} \
+ // expected-note {{use '&' for a bitwise operation}} \
+ // expected-note {{remove constant to silence this warning}}
+
+ return x && sizeof(int) == 4; // no warning, RHS is logical op.
+ return x && true;
+ return x && false;
+ return x || true;
+ return x || false;
+
+ return x && (unsigned)0; // expected-warning {{use of logical '&&' with constant operand}} \
+ // expected-note {{use '&' for a bitwise operation}} \
+ // expected-note {{remove constant to silence this warning}}
+
+ return x || (unsigned)1; // expected-warning {{use of logical '||' with constant operand}} \
+ // expected-note {{use '|' for a bitwise operation}}
+
+ return x || 0; // expected-warning {{use of logical '||' with constant operand}} \
+ // expected-note {{use '|' for a bitwise operation}}
+ return x || 1; // expected-warning {{use of logical '||' with constant operand}} \
+ // expected-note {{use '|' for a bitwise operation}}
+ return x || -1; // expected-warning {{use of logical '||' with constant operand}} \
+ // expected-note {{use '|' for a bitwise operation}}
+ return x || 5; // expected-warning {{use of logical '||' with constant operand}} \
+ // expected-note {{use '|' for a bitwise operation}}
+ return x && 0; // expected-warning {{use of logical '&&' with constant operand}} \
+ // expected-note {{use '&' for a bitwise operation}} \
+ // expected-note {{remove constant to silence this warning}}
+ return x && 1; // expected-warning {{use of logical '&&' with constant operand}} \
+ // expected-note {{use '&' for a bitwise operation}} \
+ // expected-note {{remove constant to silence this warning}}
+ return x && -1; // expected-warning {{use of logical '&&' with constant operand}} \
+ // expected-note {{use '&' for a bitwise operation}} \
+ // expected-note {{remove constant to silence this warning}}
+ return x && 5; // expected-warning {{use of logical '&&' with constant operand}} \
+ // expected-note {{use '&' for a bitwise operation}} \
+ // expected-note {{remove constant to silence this warning}}
+ return x || (0); // expected-warning {{use of logical '||' with constant operand}} \
+ // expected-note {{use '|' for a bitwise operation}}
+ return x || (1); // expected-warning {{use of logical '||' with constant operand}} \
+ // expected-note {{use '|' for a bitwise operation}}
+ return x || (-1); // expected-warning {{use of logical '||' with constant operand}} \
+ // expected-note {{use '|' for a bitwise operation}}
+ return x || (5); // expected-warning {{use of logical '||' with constant operand}} \
+ // expected-note {{use '|' for a bitwise operation}}
+ return x && (0); // expected-warning {{use of logical '&&' with constant operand}} \
+ // expected-note {{use '&' for a bitwise operation}} \
+ // expected-note {{remove constant to silence this warning}}
+ return x && (1); // expected-warning {{use of logical '&&' with constant operand}} \
+ // expected-note {{use '&' for a bitwise operation}} \
+ // expected-note {{remove constant to silence this warning}}
+ return x && (-1); // expected-warning {{use of logical '&&' with constant operand}} \
+ // expected-note {{use '&' for a bitwise operation}} \
+ // expected-note {{remove constant to silence this warning}}
+ return x && (5); // expected-warning {{use of logical '&&' with constant operand}} \
+ // expected-note {{use '&' for a bitwise operation}} \
+ // expected-note {{remove constant to silence this warning}}
+}
+
+template<unsigned int A, unsigned int B> struct S
+{
+ enum {
+ e1 = A && B,
+ e2 = A && 7 // expected-warning {{use of logical '&&' with constant operand}} \
+ // expected-note {{use '&' for a bitwise operation}} \
+ // expected-note {{remove constant to silence this warning}}
+ };
+
+ int foo() {
+ int x = A && B;
+ int y = B && 3; // expected-warning {{use of logical '&&' with constant operand}} \
+ // expected-note {{use '&' for a bitwise operation}} \
+ // expected-note {{remove constant to silence this warning}}
+
+ return x + y;
+ }
+};
+
+void test3() {
+ S<5, 8> s1;
+ S<2, 7> s2;
+ (void)s1.foo();
+ (void)s2.foo();
+}