Index: lib/Sema/SemaStmt.cpp =================================================================== --- lib/Sema/SemaStmt.cpp +++ lib/Sema/SemaStmt.cpp @@ -2843,6 +2843,7 @@ DiagnoseEmptyStmtBody(ForStmt->getRParenLoc(), B, diag::warn_empty_range_based_for_body); + DiagnoseUnusedExprResult(B); DiagnoseForRangeVariableCopies(*this, ForStmt); Index: test/SemaCXX/warn-unused-result.cpp =================================================================== --- test/SemaCXX/warn-unused-result.cpp +++ test/SemaCXX/warn-unused-result.cpp @@ -206,3 +206,13 @@ (void)++p; } } // namespace + +namespace PR39837 { +[[clang::warn_unused_result]] int f(int); + +void g() { + int a[2]; + for (int b : a) + f(b); // expected-warning {{ignoring return value}} +} +} // namespace PR39837