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.
// 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
// 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
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}}
}
};
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>();
+ }
}