summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/runnable/test16140.d
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/gdc.test/runnable/test16140.d')
-rw-r--r--gcc/testsuite/gdc.test/runnable/test16140.d32
1 files changed, 32 insertions, 0 deletions
diff --git a/gcc/testsuite/gdc.test/runnable/test16140.d b/gcc/testsuite/gdc.test/runnable/test16140.d
new file mode 100644
index 00000000000..3004945c070
--- /dev/null
+++ b/gcc/testsuite/gdc.test/runnable/test16140.d
@@ -0,0 +1,32 @@
+// https://issues.dlang.org/show_bug.cgi?id=16140
+
+int fun()
+{
+ static int count = 0;
+ if (count == 3)
+ {
+ count = 0;
+ return 0;
+ }
+ ++count;
+ return count;
+}
+
+void main()
+{
+ uint[] res;
+ while(auto value = fun())
+ res ~= value;
+ assert(res == [1, 2, 3]);
+
+ res.length = 0;
+ while(uint value = fun())
+ res ~= value;
+ assert(res == [1, 2, 3]);
+
+ res.length = 0;
+ while(const value = fun())
+ res ~= value;
+ assert(res == [1, 2, 3]);
+}
+