self-comparison.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. template <int A, int B> void foo() {
  3. (void)(A == A); // expected-warning {{self-comparison always evaluates to true}}
  4. (void)(A == B);
  5. }
  6. template <int A, int B> struct S1 {
  7. void foo() {
  8. (void)(A == A); // expected-warning {{self-comparison always evaluates to true}}
  9. (void)(A == B);
  10. }
  11. };
  12. template <int A, int B> struct S2 {
  13. template <typename T> T foo() {
  14. (void)(A == A); // expected-warning {{self-comparison always evaluates to true}}
  15. (void)(A == B);
  16. }
  17. };
  18. struct S3 {
  19. template <int A, int B> void foo() {
  20. (void)(A == A); // expected-warning {{self-comparison always evaluates to true}}
  21. (void)(A == B);
  22. }
  23. };
  24. template <int A> struct S4 {
  25. template <int B> void foo() {
  26. (void)(A == A); // expected-warning {{self-comparison always evaluates to true}}
  27. (void)(A == B);
  28. }
  29. };
  30. const int N = 42;
  31. template <int X> void foo2() {
  32. (void)(X == N);
  33. (void)(N == X);
  34. }
  35. void test() {
  36. foo<1, 1>();
  37. S1<1, 1> s1; s1.foo();
  38. S2<1, 1> s2; s2.foo<void>();
  39. S3 s3; s3.foo<1, 1>();
  40. S4<1> s4; s4.foo<1>();
  41. foo2<N>();
  42. }