aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/ext/lvalue-cond-1.C
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/g++.dg/ext/lvalue-cond-1.C')
-rw-r--r--gcc/testsuite/g++.dg/ext/lvalue-cond-1.C32
1 files changed, 32 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/ext/lvalue-cond-1.C b/gcc/testsuite/g++.dg/ext/lvalue-cond-1.C
new file mode 100644
index 00000000000..ad059afe9b6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/lvalue-cond-1.C
@@ -0,0 +1,32 @@
+/* APPLE LOCAL file non lvalue assign */
+/* Allow assignments to conditional expressions, as long as the second and third
+ operands are already lvalues. */
+/* NB: It turns out that C++ (unlike C) already allows these as lvalues, and so
+ no warnings whatsoever will be produced. */
+/* Author: Ziemowit Laski <zlaski@apple.com> */
+/* { dg-options "-fnon-lvalue-assign" } */
+/* { dg-do run } */
+
+#include <stdlib.h>
+
+int g1 = 3, g2 = 5;
+
+void assign_val1 (int which, int value) {
+ (which ? g1 : g2) = value; /* { dg-bogus "target of assignment not really an lvalue" } */
+}
+
+void assign_val2 (int which) {
+ (which ? g1 : g2)++; /* { dg-bogus "target of assignment not really an lvalue" } */
+}
+
+int main(void) {
+ assign_val1 (0, 15);
+ if (g1 != 3 || g2 != 15)
+ abort ();
+
+ assign_val2 (1);
+ if (g1 != 4 || g2 != 15)
+ abort ();
+
+ return 0;
+}