2012-05-16 00:56:36 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -Wno-constant-conversion %s
|
2009-01-20 05:37:51 +08:00
|
|
|
|
|
|
|
void choice(int);
|
|
|
|
int choice(bool);
|
|
|
|
|
|
|
|
void test() {
|
|
|
|
// Result of ! must be type bool.
|
|
|
|
int i = choice(!1);
|
|
|
|
}
|
2010-08-25 06:55:33 +08:00
|
|
|
|
|
|
|
// rdar://8018252
|
|
|
|
void f0() {
|
|
|
|
extern void f0_1(int*);
|
|
|
|
register int x;
|
|
|
|
f0_1(&x);
|
|
|
|
}
|
2010-10-12 10:19:57 +08:00
|
|
|
|
2010-10-12 11:38:33 +08:00
|
|
|
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}}
|
|
|
|
}
|
2010-10-12 10:19:57 +08:00
|
|
|
}
|
2011-05-31 13:41:42 +08:00
|
|
|
|
|
|
|
int test2(int x) {
|
2011-08-16 01:50:06 +08:00
|
|
|
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}}
|
2011-05-31 13:41:42 +08:00
|
|
|
|
|
|
|
return x && sizeof(int) == 4; // no warning, RHS is logical op.
|
|
|
|
return x && true;
|
|
|
|
return x && false;
|
|
|
|
return x || true;
|
|
|
|
return x || false;
|
|
|
|
|
2011-08-16 01:50:06 +08:00
|
|
|
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}}
|
2011-05-31 13:41:42 +08:00
|
|
|
|
2011-08-16 01:50:06 +08:00
|
|
|
return x || (unsigned)1; // expected-warning {{use of logical '||' with constant operand}} \
|
|
|
|
// expected-note {{use '|' for a bitwise operation}}
|
2011-05-31 13:41:42 +08:00
|
|
|
|
2011-08-16 01:50:06 +08:00
|
|
|
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}}
|
2011-05-31 13:41:42 +08:00
|
|
|
}
|
2011-07-15 08:00:51 +08:00
|
|
|
|
|
|
|
template<unsigned int A, unsigned int B> struct S
|
|
|
|
{
|
|
|
|
enum {
|
|
|
|
e1 = A && B,
|
2011-08-16 01:50:06 +08:00
|
|
|
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}}
|
2011-07-15 08:00:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
int foo() {
|
|
|
|
int x = A && B;
|
2011-08-16 01:50:06 +08:00
|
|
|
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}}
|
2011-07-15 08:00:51 +08:00
|
|
|
|
|
|
|
return x + y;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void test3() {
|
|
|
|
S<5, 8> s1;
|
|
|
|
S<2, 7> s2;
|
|
|
|
(void)s1.foo();
|
|
|
|
(void)s2.foo();
|
|
|
|
}
|
2014-01-15 09:53:39 +08:00
|
|
|
|
|
|
|
namespace pr16992 {
|
|
|
|
typedef int T;
|
|
|
|
unsigned getsz() {
|
|
|
|
return (sizeof T());
|
|
|
|
}
|
|
|
|
}
|