diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -8804,6 +8804,9 @@ } assert(((For && For->getBody()) || (CXXFor && CXXFor->getBody())) && "No loop body."); + // Postpone analysis in dependent contexts for ranged for loops. + if (CXXFor && SemaRef.CurContext->isDependentContext()) + return false; OpenMPIterationSpaceChecker ISC(SemaRef, SupportsNonRectangular, DSA, For ? For->getForLoc() : CXXFor->getForLoc()); diff --git a/clang/test/OpenMP/for_loop_auto.cpp b/clang/test/OpenMP/for_loop_auto.cpp new file mode 100644 --- /dev/null +++ b/clang/test/OpenMP/for_loop_auto.cpp @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -verify -fopenmp -ast-print -std=c++20 %s -Wsign-conversion | FileCheck %s +// RUN: %clang_cc1 -fopenmp -x c++ -std=c++20 -emit-pch -o %t %s +// RUN: %clang_cc1 -fopenmp -std=c++20 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s + +// RUN: %clang_cc1 -verify -fopenmp-simd -ast-print -std=c++20 %s -Wsign-conversion | FileCheck %s +// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++20 -emit-pch -o %t %s +// RUN: %clang_cc1 -fopenmp-simd -std=c++20 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s +// expected-no-diagnostics + +#ifndef HEADER +#define HEADER + +// CHECK: template <> void do_loop(const auto &v) { +// CHECK-NEXT: #pragma omp parallel for +// CHECK-NEXT: for (const auto &i : v) +// CHECK-NEXT: ; +// CHECK-NEXT: } + +void do_loop(const auto &v) { +#pragma omp parallel for + for (const auto &i : v) + ; +} +#endif