xref: /minix3/external/bsd/llvm/dist/clang/test/SemaTemplate/self-comparison.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc 
foo()3*f4a2713aSLionel Sambuc template <int A, int B> void foo() {
4*f4a2713aSLionel Sambuc   (void)(A == A); // expected-warning {{self-comparison always evaluates to true}}
5*f4a2713aSLionel Sambuc   (void)(A == B);
6*f4a2713aSLionel Sambuc }
7*f4a2713aSLionel Sambuc template <int A, int B> struct S1 {
fooS18*f4a2713aSLionel Sambuc   void foo() {
9*f4a2713aSLionel Sambuc     (void)(A == A); // expected-warning {{self-comparison always evaluates to true}}
10*f4a2713aSLionel Sambuc     (void)(A == B);
11*f4a2713aSLionel Sambuc   }
12*f4a2713aSLionel Sambuc };
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc template <int A, int B> struct S2 {
fooS215*f4a2713aSLionel Sambuc   template <typename T> T foo() {
16*f4a2713aSLionel Sambuc     (void)(A == A); // expected-warning {{self-comparison always evaluates to true}}
17*f4a2713aSLionel Sambuc     (void)(A == B);
18*f4a2713aSLionel Sambuc   }
19*f4a2713aSLionel Sambuc };
20*f4a2713aSLionel Sambuc 
21*f4a2713aSLionel Sambuc struct S3 {
fooS322*f4a2713aSLionel Sambuc   template <int A, int B> void foo() {
23*f4a2713aSLionel Sambuc     (void)(A == A); // expected-warning {{self-comparison always evaluates to true}}
24*f4a2713aSLionel Sambuc     (void)(A == B);
25*f4a2713aSLionel Sambuc   }
26*f4a2713aSLionel Sambuc };
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc template <int A> struct S4 {
fooS429*f4a2713aSLionel Sambuc   template <int B> void foo() {
30*f4a2713aSLionel Sambuc     (void)(A == A); // expected-warning {{self-comparison always evaluates to true}}
31*f4a2713aSLionel Sambuc     (void)(A == B);
32*f4a2713aSLionel Sambuc   }
33*f4a2713aSLionel Sambuc };
34*f4a2713aSLionel Sambuc 
35*f4a2713aSLionel Sambuc const int N = 42;
foo2()36*f4a2713aSLionel Sambuc template <int X> void foo2() {
37*f4a2713aSLionel Sambuc   (void)(X == N);
38*f4a2713aSLionel Sambuc   (void)(N == X);
39*f4a2713aSLionel Sambuc }
40*f4a2713aSLionel Sambuc 
test()41*f4a2713aSLionel Sambuc void test() {
42*f4a2713aSLionel Sambuc   foo<1, 1>();
43*f4a2713aSLionel Sambuc   S1<1, 1> s1; s1.foo();
44*f4a2713aSLionel Sambuc   S2<1, 1> s2; s2.foo<void>();
45*f4a2713aSLionel Sambuc   S3 s3; s3.foo<1, 1>();
46*f4a2713aSLionel Sambuc   S4<1> s4; s4.foo<1>();
47*f4a2713aSLionel Sambuc   foo2<N>();
48*f4a2713aSLionel Sambuc }
49