diff options
author | Zancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au> | 2012-09-24 09:58:17 +1000 |
---|---|---|
committer | Zancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au> | 2012-09-24 09:58:17 +1000 |
commit | 222e2a7620e6520ffaf4fc4e69d79c18da31542e (patch) | |
tree | 7bfbc05bfa3b41c8f9d2e56d53a0bc3e310df239 /clang/test/SemaCXX/warn-sign-conversion.cpp | |
parent | 3d206f03985b50beacae843d880bccdc91a9f424 (diff) |
Add the clang library to the repo (with some of my changes, too).
Diffstat (limited to 'clang/test/SemaCXX/warn-sign-conversion.cpp')
-rw-r--r-- | clang/test/SemaCXX/warn-sign-conversion.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/warn-sign-conversion.cpp b/clang/test/SemaCXX/warn-sign-conversion.cpp new file mode 100644 index 0000000..ba2bc9b --- /dev/null +++ b/clang/test/SemaCXX/warn-sign-conversion.cpp @@ -0,0 +1,80 @@ +// RUN: %clang_cc1 -verify -fsyntax-only -Wsign-conversion %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 d1a = 1 ? i : Foo<bool>::D; // expected-warning {{test1::Foo<bool>::<anonymous enum at }} + int d1b = 1 ? i : Foo<bool>::D; // expected-warning {{warn-sign-conversion.cpp:13:5>' to 'int'}} + int d2a = 1 ? Foo<bool>::D : i; // expected-warning {{operand of ? changes signedness: 'test1::Foo<bool>::<anonymous enum at }} + int d2b = 1 ? Foo<bool>::D : i; // expected-warning {{warn-sign-conversion.cpp:13:5>' to 'int'}} + int d3a = 1 ? B : Foo<bool>::D; // expected-warning {{operand of ? changes signedness: 'test1::Foo<bool>::<anonymous enum at }} + int d3b = 1 ? B : Foo<bool>::D; // expected-warning {{warn-sign-conversion.cpp:13:5>' to 'int'}} + int d4a = 1 ? Foo<bool>::D : B; // expected-warning {{operand of ? changes signedness: 'test1::Foo<bool>::<anonymous enum at }} + int d4b = 1 ? Foo<bool>::D : B; // expected-warning {{warn-sign-conversion.cpp:13:5>' to 'int'}} + + int e1a = 1 ? i : E; // expected-warning {{operand of ? changes signedness: 'test1::<anonymous enum at }} + int e1b = 1 ? i : E; // expected-warning {{warn-sign-conversion.cpp:16:3>' to 'int'}} + int e2a = 1 ? E : i; // expected-warning {{operand of ? changes signedness: 'test1::<anonymous enum at }} + int e2b = 1 ? E : i; // expected-warning {{warn-sign-conversion.cpp:16:3>' to 'int'}} + int e3a = 1 ? E : B; // expected-warning {{operand of ? changes signedness: 'test1::<anonymous enum at }} + int e3b = 1 ? E : B; // expected-warning {{warn-sign-conversion.cpp:16:3>' to 'int'}} + int e4a = 1 ? B : E; // expected-warning {{operand of ? changes signedness: 'test1::<anonymous enum at }} + int e4b = 1 ? B : E; // expected-warning {{warn-sign-conversion.cpp:16:3>' to 'int'}} + } +} + +// 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 {{operand of ? changes signedness: 'test2::Foo<bool>::Named4' to 'int'}} + int d2 = 1 ? Foo<bool>::D : i; // expected-warning {{operand of ? changes signedness: 'test2::Foo<bool>::Named4' to 'int'}} + int d3 = 1 ? B : Foo<bool>::D; // expected-warning {{operand of ? changes signedness: 'test2::Foo<bool>::Named4' to 'int'}} + int d4 = 1 ? Foo<bool>::D : B; // expected-warning {{operand of ? changes signedness: 'test2::Foo<bool>::Named4' to 'int'}} + + int e1 = 1 ? i : E; // expected-warning {{operand of ? changes signedness: 'test2::Named5' to 'int'}} + int e2 = 1 ? E : i; // expected-warning {{operand of ? changes signedness: 'test2::Named5' to 'int'}} + int e3 = 1 ? E : B; // expected-warning {{operand of ? changes signedness: 'test2::Named5' to 'int'}} + int e4 = 1 ? B : E; // expected-warning {{operand of ? changes signedness: 'test2::Named5' to 'int'}} + } +} |