r193906 - Change the other -Wtautological-compare warnings to not trigger in template
Richard Trieu
rtrieu at google.com
Fri Nov 1 19:11:23 PDT 2013
Author: rtrieu
Date: Fri Nov 1 21:11:23 2013
New Revision: 193906
URL: http://llvm.org/viewvc/llvm-project?rev=193906&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/PCH/pragma-diag-section.cpp
cfe/trunk/test/SemaCXX/compare.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=193906&r1=193905&r2=193906&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Nov 1 21:11:23 2013
@@ -7665,7 +7665,8 @@ QualType Sema::CheckCompareOperands(Expr
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::CheckVectorCompareOperand
// 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
Modified: cfe/trunk/test/PCH/pragma-diag-section.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/pragma-diag-section.cpp?rev=193906&r1=193905&r2=193906&view=diff
==============================================================================
--- cfe/trunk/test/PCH/pragma-diag-section.cpp (original)
+++ cfe/trunk/test/PCH/pragma-diag-section.cpp Fri Nov 1 21:11:23 2013
@@ -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 at 39 {{in instantiation of member function}}
+ T a;
+ T b = a; // expected-warning {{variable 'a' is uninitialized}} \
+ expected-note at 41 {{in instantiation of member function}} \
+ expected-note at 28 {{initialize the variable 'a' to silence}}
}
};
Modified: cfe/trunk/test/SemaCXX/compare.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/compare.cpp?rev=193906&r1=193905&r2=193906&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/compare.cpp (original)
+++ cfe/trunk/test/SemaCXX/compare.cpp Fri Nov 1 21:11:23 2013
@@ -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>();
+ }
}
More information about the cfe-commits
mailing list