[cfe-commits] r98975 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/SemaCXX/conditional-expr.cpp test/SemaCXX/warn-sign-compare.cpp
John McCall
rjmccall at apple.com
Fri Mar 19 11:53:26 PDT 2010
Author: rjmccall
Date: Fri Mar 19 13:53:26 2010
New Revision: 98975
URL: http://llvm.org/viewvc/llvm-project?rev=98975&view=rev
Log:
Promote enum types during -Wsign-compare. Fixes some spurious warnings,
mostly during conditional expressions.
Added:
cfe/trunk/test/SemaCXX/warn-sign-compare.cpp
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaCXX/conditional-expr.cpp
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=98975&r1=98974&r2=98975&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Mar 19 13:53:26 2010
@@ -2045,6 +2045,11 @@
if (!tmp.isNull()) rt = tmp;
}
+ if (const EnumType *E = lt->getAs<EnumType>())
+ lt = E->getDecl()->getPromotionType();
+ if (const EnumType *E = rt->getAs<EnumType>())
+ rt = E->getDecl()->getPromotionType();
+
// The rule is that the signed operand becomes unsigned, so isolate the
// signed operand.
Expr *signedOperand = lex, *unsignedOperand = rex;
Modified: cfe/trunk/test/SemaCXX/conditional-expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/conditional-expr.cpp?rev=98975&r1=98974&r2=98975&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/conditional-expr.cpp (original)
+++ cfe/trunk/test/SemaCXX/conditional-expr.cpp Fri Mar 19 13:53:26 2010
@@ -154,8 +154,8 @@
i1 = i1 ? i1 : ir1;
int *pi1 = i1 ? &i1 : 0;
pi1 = i1 ? 0 : &i1;
- i1 = i1 ? i1 : EVal; // expected-warning {{operands of ? are integers of different signs}} ??
- i1 = i1 ? EVal : i1; // expected-warning {{operands of ? are integers of different signs}} ??
+ i1 = i1 ? i1 : EVal;
+ i1 = i1 ? EVal : i1;
d1 = i1 ? 'c' : 4.0;
d1 = i1 ? 4.0 : 'c';
Base *pb = i1 ? (Base*)0 : (Derived*)0;
@@ -191,7 +191,7 @@
test0 = test0 ? (short) 10 : test0;
test0 = test0 ? EVal : test0;
- test0 = test0 ? EVal : (int) test0; // expected-warning {{operands of ? are integers of different signs}}
+ test0 = test0 ? EVal : (int) test0;
// Note the thing that this does not test: since DR446, various situations
// *must* create a separate temporary copy of class objects. This can only
Added: cfe/trunk/test/SemaCXX/warn-sign-compare.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-sign-compare.cpp?rev=98975&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-sign-compare.cpp (added)
+++ cfe/trunk/test/SemaCXX/warn-sign-compare.cpp Fri Mar 19 13:53:26 2010
@@ -0,0 +1,72 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -Wsign-compare %s
+
+// NOTE: When a 'enumeral mismatch' warning is implemented then expect several
+// of the following cases to be impacted.
+
+// namespace for anonymous enums tests
+namespace test1 {
+ enum { A };
+ enum { B = -1 };
+
+ template <typename T> struct Foo {
+ enum { C };
+ enum { D = ~0U };
+ };
+
+ enum { E = ~0U };
+
+ void doit_anonymous( int i ) {
+ int a1 = 1 ? i : A;
+ int a2 = 1 ? A : i;
+
+ int b1 = 1 ? i : B;
+ int b2 = 1 ? B : i;
+
+ int c1 = 1 ? i : Foo<bool>::C;
+ int c2 = 1 ? Foo<bool>::C : i;
+
+ int d1 = 1 ? i : Foo<bool>::D; // expected-warning {{operands of ? are integers of different signs}}
+ int d2 = 1 ? Foo<bool>::D : i; // expected-warning {{operands of ? are integers of different signs}}
+ int d3 = 1 ? B : Foo<bool>::D; // expected-warning {{operands of ? are integers of different signs}}
+ int d4 = 1 ? Foo<bool>::D : B; // expected-warning {{operands of ? are integers of different signs}}
+
+ int e1 = 1 ? i : E; // expected-warning {{operands of ? are integers of different signs}}
+ int e2 = 1 ? E : i; // expected-warning {{operands of ? are integers of different signs}}
+ int e3 = 1 ? E : B; // expected-warning {{operands of ? are integers of different signs}}
+ int e4 = 1 ? B : E; // expected-warning {{operands of ? are integers of different signs}}
+ }
+}
+
+// namespace for named enums tests
+namespace test2 {
+ enum Named1 { A };
+ enum Named2 { B = -1 };
+
+ template <typename T> struct Foo {
+ enum Named3 { C };
+ enum Named4 { D = ~0U };
+ };
+
+ enum Named5 { E = ~0U };
+
+ void doit_anonymous( int i ) {
+ int a1 = 1 ? i : A;
+ int a2 = 1 ? A : i;
+
+ int b1 = 1 ? i : B;
+ int b2 = 1 ? B : i;
+
+ int c1 = 1 ? i : Foo<bool>::C;
+ int c2 = 1 ? Foo<bool>::C : i;
+
+ int d1 = 1 ? i : Foo<bool>::D; // expected-warning {{operands of ? are integers of different signs}}
+ int d2 = 1 ? Foo<bool>::D : i; // expected-warning {{operands of ? are integers of different signs}}
+ int d3 = 1 ? B : Foo<bool>::D; // expected-warning {{operands of ? are integers of different signs}}
+ int d4 = 1 ? Foo<bool>::D : B; // expected-warning {{operands of ? are integers of different signs}}
+
+ int e1 = 1 ? i : E; // expected-warning {{operands of ? are integers of different signs}}
+ int e2 = 1 ? E : i; // expected-warning {{operands of ? are integers of different signs}}
+ int e3 = 1 ? E : B; // expected-warning {{operands of ? are integers of different signs}}
+ int e4 = 1 ? B : E; // expected-warning {{operands of ? are integers of different signs}}
+ }
+}
More information about the cfe-commits
mailing list