diff options
| author | Richard Trieu <rtrieu@google.com> | 2013-11-01 21:19:43 +0000 |
|---|---|---|
| committer | Richard Trieu <rtrieu@google.com> | 2013-11-01 21:19:43 +0000 |
| commit | dd51d747bf8f5424496f7948c38f6ca42567f5c4 (patch) | |
| tree | 0a170dcda1939b23fa2a1c85f8de8f7fd0dd64bc /clang | |
| parent | 450f422b49853c4ad74d80331902faedaf841fa2 (diff) | |
| download | bcm5719-llvm-dd51d747bf8f5424496f7948c38f6ca42567f5c4.tar.gz bcm5719-llvm-dd51d747bf8f5424496f7948c38f6ca42567f5c4.zip | |
Disable -Wtautological-constant-out-of-range-compare in template instantiations.
llvm-svn: 193887
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 4 | ||||
| -rw-r--r-- | clang/test/SemaCXX/compare.cpp | 26 |
2 files changed, 30 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index aa9ba2c8e68..772fee32ceb 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -4806,6 +4806,10 @@ static void DiagnoseOutOfRangeComparison(Sema &S, BinaryOperator *E, 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/clang/test/SemaCXX/compare.cpp b/clang/test/SemaCXX/compare.cpp index feb1ccb9a20..22f2565882c 100644 --- a/clang/test/SemaCXX/compare.cpp +++ b/clang/test/SemaCXX/compare.cpp @@ -355,3 +355,29 @@ 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); + } +} |

