[OPENMP]Fix PR51327: Range based for loop not working if range's type is a template.

Need to postpone anlysis of the ranged for loops till the actual
instantiation to avoid erroneous emission of error messages.

Differential Revision: https://reviews.llvm.org/D114560
This commit is contained in:
Alexey Bataev 2021-11-24 11:21:10 -08:00
parent 75dfeef9ad
commit a0839c13fd
2 changed files with 27 additions and 0 deletions

View File

@ -8804,6 +8804,9 @@ static bool checkOpenMPIterationSpace(
}
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());

View File

@ -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