r193887 - Disable -Wtautological-constant-out-of-range-compare in template instantiations.
Richard Smith
richard at metafoo.co.uk
Fri Nov 1 14:54:44 PDT 2013
Maybe you want to close PR8682? =)
On Fri, Nov 1, 2013 at 2:19 PM, Richard Trieu <rtrieu at google.com> wrote:
> Author: rtrieu
> Date: Fri Nov 1 16:19:43 2013
> New Revision: 193887
>
> URL: http://llvm.org/viewvc/llvm-project?rev=193887&view=rev
> Log:
> Disable -Wtautological-constant-out-of-range-compare in template
> instantiations.
>
> Modified:
> cfe/trunk/lib/Sema/SemaChecking.cpp
> cfe/trunk/test/SemaCXX/compare.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=193887&r1=193886&r2=193887&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Nov 1 16:19:43 2013
> @@ -4806,6 +4806,10 @@ static void DiagnoseOutOfRangeComparison
> 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;
>
> Modified: cfe/trunk/test/SemaCXX/compare.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/compare.cpp?rev=193887&r1=193886&r2=193887&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/compare.cpp (original)
> +++ cfe/trunk/test/SemaCXX/compare.cpp Fri Nov 1 16:19:43 2013
> @@ -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);
> + }
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131101/90ebf3cf/attachment.html>
More information about the cfe-commits
mailing list