Disable -Wtautological-constant-out-of-range-compare in template instantiations.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193887 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index aa9ba2c..772fee3 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -4806,6 +4806,10 @@
                                          Expr *Constant, Expr *Other,
                                          llvm::APSInt Value,
                                          bool RhsConstant) {
+  // Disable warning in template instantiations.
+  if (!S.ActiveTemplateInstantiations.empty())
+    return;
+
   // 0 values are handled later by CheckTrivialUnsignedComparison().
   if (Value == 0)
     return;
diff --git a/test/SemaCXX/compare.cpp b/test/SemaCXX/compare.cpp
index feb1ccb..22f2565 100644
--- a/test/SemaCXX/compare.cpp
+++ b/test/SemaCXX/compare.cpp
@@ -355,3 +355,29 @@
   };
   (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);
+  }
+}