Added operator overloading for unary operators, post-increment, and
post-decrement, including support for generating all of the built-in
operator candidates for these operators.
C++ and C have different rules for the arguments to the builtin unary
'+' and '-'. Implemented both variants in Sema::ActOnUnaryOp.
In C++, pre-increment and pre-decrement return lvalues. Update
Expr::isLvalue accordingly.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59638 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/SemaCXX/overloaded-builtin-operators.cpp b/test/SemaCXX/overloaded-builtin-operators.cpp
index af328da..29d721c 100644
--- a/test/SemaCXX/overloaded-builtin-operators.cpp
+++ b/test/SemaCXX/overloaded-builtin-operators.cpp
@@ -25,6 +25,14 @@
no& islong(int);
void f(Short s, Long l, Enum1 e1, Enum2 e2) {
+ // C++ [over.built]p8
+ int i1 = +e1;
+ int i2 = -e2;
+
+ // C++ [over.built]p10:
+ int i3 = ~s;
+ bool b1 = !s;
+
// C++ [over.built]p12
(void)static_cast<yes&>(islong(s + l));
(void)static_cast<no&>(islong(s + s));
@@ -46,6 +54,12 @@
};
void g(ShortRef sr, LongRef lr) {
+ // C++ [over.built]p3
+ short s1 = sr++;
+
+ // C++ [over.built]p3
+ long l1 = lr--;
+
// C++ [over.built]p18
short& sr1 = (sr *= lr);
volatile long& lr1 = (lr *= sr);
@@ -65,7 +79,16 @@
operator int const *();
};
-void test_with_ptrs(VolatileIntPtr vip, ConstIntPtr cip, ShortRef sr) {
+struct VolatileIntPtrRef {
+ operator int volatile *&();
+};
+
+struct ConstIntPtrRef {
+ operator int const *&();
+};
+
+void test_with_ptrs(VolatileIntPtr vip, ConstIntPtr cip, ShortRef sr,
+ VolatileIntPtrRef vipr, ConstIntPtrRef cipr) {
#if 0
// FIXME: Enable these tests once we have operator overloading for
// operator[].
@@ -76,4 +99,19 @@
#endif
bool b1 = (vip == cip);
long p1 = vip - cip;
+
+ // C++ [over.built]p5:
+ int volatile *vip1 = vipr++;
+ int const *cip1 = cipr++;
+ int volatile *&vipr1 = ++vipr;
+ int const *&cipr1 = --cipr;
+
+ // C++ [over.built]p6:
+ int volatile &ivr = *vip;
+
+ // C++ [over.built]p8:
+ int volatile *vip2 = +vip;
+ int i1 = +sr;
+ int i2 = -sr;
}
+