From 14af91a38c8cf89f0a5e1835d7d8e0fa220e17a9 Mon Sep 17 00:00:00 2001
From: Douglas Gregor <dgregor@apple.com>
Date: Tue, 21 Dec 2010 07:22:56 +0000
Subject: [PATCH] Don't try to compute the value of a value-dependent
 expression when checking trivial comparisons. Fixes PR8795.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@122322 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Sema/SemaChecking.cpp            |  3 +++
 test/SemaTemplate/dependent-expr.cpp | 10 ++++++++++
 2 files changed, 13 insertions(+)

diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index c75b27c3ecc..75b30fcb769 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -2527,6 +2527,9 @@ static bool HasEnumType(Expr *E) {
 
 void CheckTrivialUnsignedComparison(Sema &S, BinaryOperator *E) {
   BinaryOperatorKind op = E->getOpcode();
+  if (E->isValueDependent())
+    return;
+
   if (op == BO_LT && IsZero(S, E->getRHS())) {
     S.Diag(E->getOperatorLoc(), diag::warn_lunsigned_always_true_comparison)
       << "< 0" << "false" << HasEnumType(E->getLHS())
diff --git a/test/SemaTemplate/dependent-expr.cpp b/test/SemaTemplate/dependent-expr.cpp
index f26c85b1ecc..a1ddd249f7f 100644
--- a/test/SemaTemplate/dependent-expr.cpp
+++ b/test/SemaTemplate/dependent-expr.cpp
@@ -61,3 +61,13 @@ namespace test5 {
     }
   };
 }
+
+namespace PR8795 {
+  template <class _CharT> int test(_CharT t)
+  {
+    int data [] = {
+      sizeof(_CharT) > sizeof(char)
+    };
+    return data[0];
+  }
+}
-- 
GitLab