summaryrefslogtreecommitdiffstats
path: root/test/SemaCXX/compare.cpp
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2013-12-22 00:07:40 +0000
committerdim <dim@FreeBSD.org>2013-12-22 00:07:40 +0000
commit952eddef9aff85b1e92626e89baaf7a360e2ac85 (patch)
treedf8df0b0067b381eab470a3b8f28d14a552a6340 /test/SemaCXX/compare.cpp
parentea266cad53e3d49771fa38103913d3ec7a166694 (diff)
downloadFreeBSD-src-952eddef9aff85b1e92626e89baaf7a360e2ac85.zip
FreeBSD-src-952eddef9aff85b1e92626e89baaf7a360e2ac85.tar.gz
Vendor import of clang release_34 branch r197841 (effectively, 3.4 RC3):
https://llvm.org/svn/llvm-project/cfe/branches/release_34@197841
Diffstat (limited to 'test/SemaCXX/compare.cpp')
-rw-r--r--test/SemaCXX/compare.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/test/SemaCXX/compare.cpp b/test/SemaCXX/compare.cpp
index feb1ccb..8214f78 100644
--- a/test/SemaCXX/compare.cpp
+++ b/test/SemaCXX/compare.cpp
@@ -355,3 +355,70 @@ void test9(int x) {
};
(void)((E)x == 1);
}
+
+namespace templates {
+ template<class T> T max();
+
+ template<> constexpr int max<int>() { return 2147483647; };
+
+ template<typename T>
+ bool less_than_max(short num, T value) {
+ const T vmax = max<T>();
+ return (vmax >= num); // no warning
+ }
+
+ template<typename T>
+ bool less_than_max(short num) {
+ // This should trigger one warning on the template pattern, and not a
+ // warning per specialization.
+ return num < max<int>(); // expected-warning{{comparison of constant 2147483647 with expression of type 'short' is always true}}
+ }
+
+ void test10(short num, int x) {
+ less_than_max(num, x);
+ less_than_max<int>(num);
+ less_than_max<long>(num);
+ less_than_max<short>(num);
+ }
+
+ template<typename T>
+ inline bool less_than_zero(T num, T value) {
+ return num < 0; // no warning
+ }
+
+ template<typename T>
+ inline bool less_than_zero(unsigned num) {
+ // This should trigger one warning on the template pattern, and not a
+ // warning per specialization.
+ return num < 0; // expected-warning{{comparison of unsigned expression < 0 is always false}}
+ }
+
+ void test11(unsigned num) {
+ less_than_zero(num, num);
+ less_than_zero<int>(num);
+ less_than_zero<long>(num);
+ less_than_zero<short>(num);
+ }
+
+ template<unsigned n> bool compare(unsigned k) { return k >= n; }
+
+ void test12() {
+ compare<0>(42);
+ }
+
+ struct A { static int x; };
+ struct B { static int x; };
+ typedef A otherA;
+
+ template <typename T>
+ void testx() {
+ if (A::x == T::x && // no warning
+ A::x == otherA::x) // expected-warning{{self-comparison always evaluates to true}}
+ return;
+ }
+
+ void test13() {
+ testx<A>();
+ testx<B>();
+ }
+}
OpenPOWER on IntegriCloud