aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/warn/Wunreachable-code-1.C
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/g++.dg/warn/Wunreachable-code-1.C')
-rw-r--r--gcc/testsuite/g++.dg/warn/Wunreachable-code-1.C22
1 files changed, 22 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/warn/Wunreachable-code-1.C b/gcc/testsuite/g++.dg/warn/Wunreachable-code-1.C
new file mode 100644
index 00000000000..23fc86dfbb2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wunreachable-code-1.C
@@ -0,0 +1,22 @@
+/* PR17544 Incorrect -Wunreachable-code warning
+ Origin: sebor@roguewave.com
+
+ G++ appends a "return 0;" when finishing a function, but it was not
+ given a source location. The gimplifier thinks a return statement
+ needs a locus so it would add one, making the compiler generated code
+ visible to the unreachable code warning. */
+
+/* { dg-do compile } */
+/* { dg-options "-O -Wunreachable-code" } */
+
+int
+main (int argc, char *argv[])
+{
+ const char* const s = argc < 2 ? "" : argv [1];
+ int i = 0;
+ do {
+ ++i;
+ } while (i < s [0]);
+ return i;
+}
+