summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Trieu <rtrieu@google.com>2013-11-02 02:11:23 +0000
committerRichard Trieu <rtrieu@google.com>2013-11-02 02:11:23 +0000
commit30bfa3623b6ec59fc03cba486040eef77cd5f847 (patch)
tree292f2127404cf21d975d0751b37a6678979f3b9b
parente4aaa335dd590bdb5875ecfc22beb55461604273 (diff)
downloadbcm5719-llvm-30bfa3623b6ec59fc03cba486040eef77cd5f847.tar.gz
bcm5719-llvm-30bfa3623b6ec59fc03cba486040eef77cd5f847.zip
Change the other -Wtautological-compare warnings to not trigger in template
specializations. Also switch to -Wuninitialized for a test case that depended on a warning firing in template specializations. llvm-svn: 193906
-rw-r--r--clang/lib/Sema/SemaExpr.cpp6
-rw-r--r--clang/test/PCH/pragma-diag-section.cpp16
-rw-r--r--clang/test/SemaCXX/compare.cpp16
3 files changed, 29 insertions, 9 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 77cf986351d..edae0147d50 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -7665,7 +7665,8 @@ QualType Sema::CheckCompareOperands(ExprResult &LHS, ExprResult &RHS,
if (!LHSType->hasFloatingRepresentation() &&
!(LHSType->isBlockPointerType() && IsRelational) &&
!LHS.get()->getLocStart().isMacroID() &&
- !RHS.get()->getLocStart().isMacroID()) {
+ !RHS.get()->getLocStart().isMacroID() &&
+ ActiveTemplateInstantiations.empty()) {
// For non-floating point types, check for self-comparisons of the form
// x == x, x != x, x < x, etc. These always evaluate to a constant, and
// often indicate logic errors in the program.
@@ -8051,7 +8052,8 @@ QualType Sema::CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS,
// For non-floating point types, check for self-comparisons of the form
// x == x, x != x, x < x, etc. These always evaluate to a constant, and
// often indicate logic errors in the program.
- if (!LHSType->hasFloatingRepresentation()) {
+ if (!LHSType->hasFloatingRepresentation() &&
+ ActiveTemplateInstantiations.empty()) {
if (DeclRefExpr* DRL
= dyn_cast<DeclRefExpr>(LHS.get()->IgnoreParenImpCasts()))
if (DeclRefExpr* DRR
diff --git a/clang/test/PCH/pragma-diag-section.cpp b/clang/test/PCH/pragma-diag-section.cpp
index 627156f1539..eea6bd73f54 100644
--- a/clang/test/PCH/pragma-diag-section.cpp
+++ b/clang/test/PCH/pragma-diag-section.cpp
@@ -1,20 +1,20 @@
// Test this without pch.
-// RUN: %clang_cc1 %s -include %s -verify -fsyntax-only
+// RUN: %clang_cc1 %s -include %s -verify -fsyntax-only -Wuninitialized
// Test with pch.
// RUN: %clang_cc1 %s -emit-pch -o %t
-// RUN: %clang_cc1 %s -include-pch %t -verify -fsyntax-only
+// RUN: %clang_cc1 %s -include-pch %t -verify -fsyntax-only -Wuninitialized
#ifndef HEADER
#define HEADER
#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wtautological-compare"
+#pragma clang diagnostic ignored "-Wuninitialized"
template <typename T>
struct TS1 {
void m() {
- T a = 0;
- T b = a==a;
+ T a;
+ T b = a;
}
};
#pragma clang diagnostic pop
@@ -25,8 +25,10 @@ struct TS1 {
template <typename T>
struct TS2 {
void m() {
- T a = 0;
- T b = a==a; // expected-warning {{self-comparison always evaluates to true}} expected-note@39 {{in instantiation of member function}}
+ T a;
+ T b = a; // expected-warning {{variable 'a' is uninitialized}} \
+ expected-note@41 {{in instantiation of member function}} \
+ expected-note@28 {{initialize the variable 'a' to silence}}
}
};
diff --git a/clang/test/SemaCXX/compare.cpp b/clang/test/SemaCXX/compare.cpp
index 02b029a7762..8214f7899ec 100644
--- a/clang/test/SemaCXX/compare.cpp
+++ b/clang/test/SemaCXX/compare.cpp
@@ -405,4 +405,20 @@ namespace templates {
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