summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/warn/Warray-bounds-5.C
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/g++.dg/warn/Warray-bounds-5.C')
-rw-r--r--gcc/testsuite/g++.dg/warn/Warray-bounds-5.C24
1 files changed, 24 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/warn/Warray-bounds-5.C b/gcc/testsuite/g++.dg/warn/Warray-bounds-5.C
new file mode 100644
index 000000000..06d776a40
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Warray-bounds-5.C
@@ -0,0 +1,24 @@
+// { dg-do compile }
+// { dg-options "-O2 -Warray-bounds" }
+
+void f();
+
+int c[3];
+int result;
+
+struct Vector {
+ static int get(int i) {
+ if (i >= 3)
+ f();
+ return c[i];
+ }
+};
+
+void g()
+{
+ for (int i = 0; i < 3; ++i) {
+ const int index = i % 3;
+ result = Vector::get(index) + Vector::get(index);
+ }
+}
+