summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Sema/enum-increment.c13
-rw-r--r--clang/test/SemaCXX/enum-increment.cpp16
2 files changed, 29 insertions, 0 deletions
diff --git a/clang/test/Sema/enum-increment.c b/clang/test/Sema/enum-increment.c
new file mode 100644
index 00000000000..baaa3489b95
--- /dev/null
+++ b/clang/test/Sema/enum-increment.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+// expected-no-diagnostics
+enum A { A1, A2, A3 };
+typedef enum A A;
+void test() {
+ A a;
+ a++;
+ a--;
+ ++a;
+ --a;
+ a = a + 1;
+ a = a - 1;
+}
diff --git a/clang/test/SemaCXX/enum-increment.cpp b/clang/test/SemaCXX/enum-increment.cpp
new file mode 100644
index 00000000000..dc1a921852e
--- /dev/null
+++ b/clang/test/SemaCXX/enum-increment.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+
+enum A { A1, A2, A3 };
+void test() {
+ A a;
+ a++; // expected-error{{cannot increment expression of enum type 'A'}}
+ a--; // expected-error{{cannot decrement expression of enum type 'A'}}
+ ++a; // expected-error{{cannot increment expression of enum type 'A'}}
+ --a; // expected-error{{cannot decrement expression of enum type 'A'}}
+}
+
+enum B {B1, B2};
+inline B &operator++ (B &b) { b = B((int)b+1); return b; }
+inline B operator++ (B &b, int) { B ret = b; ++b; return b; }
+
+void foo(enum B b) { ++b; b++; }
OpenPOWER on IntegriCloud