aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-03-05 20:21:48 +0100
committerChristopher Li <sparse@chrisli.org>2017-03-06 08:48:03 +0800
commit9af83dd11730f0a384106b0944b5982d539e59ff (patch)
treef1588d7ed7be1f81d64d1e1e63b2bbbf011562d0
parentfdd39251681b5f8374695a39581c982d7ea4faff (diff)
downloadsparse-9af83dd11730f0a384106b0944b5982d539e59ff.tar.gz
add test case for scope of C99 for-loop declarations
Insure that variable declared inside a C99 for-loop have their scope restricted to this loop. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> Signed-off-by: Christopher Li <sparse@chrisli.org>
-rw-r--r--validation/c99-for-loop-decl.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/validation/c99-for-loop-decl.c b/validation/c99-for-loop-decl.c
new file mode 100644
index 00000000..c2ceaab9
--- /dev/null
+++ b/validation/c99-for-loop-decl.c
@@ -0,0 +1,18 @@
+static int bad_scope(void)
+{
+ int r = 0;
+
+ for (int i = 0; i < 10; i++) {
+ r = i;
+ }
+
+ return i; /* check-should-fail */
+}
+
+/*
+ * check-name: C99 for-loop declarations
+ *
+ * check-error-start
+c99-for-loop-decl.c:9:16: error: undefined identifier 'i'
+ * check-error-end
+ */