aboutsummaryrefslogtreecommitdiff
path: root/test/SemaCXX/enum.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2009-12-09 09:09:27 +0000
committerJohn McCall <rjmccall@apple.com>2009-12-09 09:09:27 +0000
commit842aef8d942a880eeb9535d40de31a86838264cb (patch)
tree389c0e27fb6c98f56bce032e96f43ba8bcd8041b /test/SemaCXX/enum.cpp
parent2f4a6b25a7409f6f05e8a5e6864de21a337c8958 (diff)
First pass at implementing C++ enum semantics: calculate (and store) an
"integer promotion" type associated with an enum decl, and use this type to determine which type to promote to. This type obeys C++ [conv.prom]p2 and is therefore generally signed unless the range of the enumerators forces it to be unsigned. Kills off a lot of false positives from -Wsign-compare in C++, addressing rdar://7455616 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90965 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/enum.cpp')
-rw-r--r--test/SemaCXX/enum.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/SemaCXX/enum.cpp b/test/SemaCXX/enum.cpp
index 1aba107a69..3315de00ca 100644
--- a/test/SemaCXX/enum.cpp
+++ b/test/SemaCXX/enum.cpp
@@ -1,4 +1,5 @@
// RUN: clang-cc -fsyntax-only -verify %s
+
enum E {
Val1,
Val2
@@ -35,3 +36,32 @@ static enum e1 badfunc(struct s1 *q) {
}
enum e2; // expected-error{{ISO C++ forbids forward references to 'enum' types}}
+
+namespace test1 {
+ template <class A, class B> struct is_same { static const int value = -1; };
+ template <class A> struct is_same<A,A> { static const int value = 1; };
+
+ enum enum0 { v0 };
+ int test0[is_same<typeof(+v0), int>::value];
+
+ enum enum1 { v1 = __INT_MAX__ };
+ int test1[is_same<typeof(+v1), int>::value];
+
+ enum enum2 { v2 = __INT_MAX__ * 2U };
+ int test2[is_same<typeof(+v2), unsigned int>::value];
+
+ // This kindof assumes that 'int' is smaller than 'long long'.
+#if defined(__LP64__)
+ enum enum3 { v3 = __LONG_LONG_MAX__ };
+ int test3[is_same<typeof(+v3), long>::value];
+
+ enum enum4 { v4 = __LONG_LONG_MAX__ * 2ULL };
+ int test4[is_same<typeof(+v4), unsigned long>::value];
+#else
+ enum enum3 { v3 = __LONG_LONG_MAX__ };
+ int test3[is_same<typeof(+v3), long long>::value];
+
+ enum enum4 { v4 = __LONG_LONG_MAX__ * 2ULL };
+ int test4[is_same<typeof(+v4), unsigned long long>::value];
+#endif
+}