<!--{
"Title": "The Go Programming Language Specification",
- "Subtitle": "Version of Sep 16, 2021",
+ "Subtitle": "Version of Oct 15, 2021",
"Path": "/ref/spec"
}-->
A <a href="#For_statements">"for" statement</a> in which:
<ul>
<li>there are no "break" statements referring to the "for" statement, and</li>
- <li>the loop condition is absent.</li>
+ <li>the loop condition is absent, and</li>
+ <li>the "for" statement does not use a range clause.</li>
</ul>
</li>
return true
case *syntax.ForStmt:
+ if _, ok := s.Init.(*syntax.RangeClause); ok {
+ // Range clauses guarantee that the loop terminates,
+ // so the loop is not a terminating statement. See issue 49003.
+ break
+ }
if s.Cond == nil && !hasBreak(s.Body, label, true) {
return true
}
--- /dev/null
+// errorcheck
+
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+func f(s string) int {
+ for range s {
+ }
+} // ERROR "missing return"