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 @@ -15902,20 +15902,24 @@ continue; } - auto *ASE = dyn_cast(SimpleExpr); - if (!RefExpr->IgnoreParenImpCasts()->isLValue() || - (ASE && - !ASE->getBase() - ->getType() - .getNonReferenceType() - ->isPointerType() && - !ASE->getBase()->getType().getNonReferenceType()->isArrayType())) { + if (!RefExpr->IgnoreParenImpCasts()->isLValue()) { Diag(ELoc, diag::err_omp_expected_addressable_lvalue_or_array_item) << (LangOpts.OpenMP >= 50 ? 1 : 0) << (LangOpts.OpenMP >= 50 ? 1 : 0) << RefExpr->getSourceRange(); continue; } + if (auto *ASE = dyn_cast(SimpleExpr)) { + QualType BaseType = ASE->getBase()->getType().getNonReferenceType(); + if (!BaseType->isDependentType() && !BaseType->isPointerType() && + !BaseType->isArrayType()) { + Diag(ELoc, diag::err_omp_expected_addressable_lvalue_or_array_item) + << (LangOpts.OpenMP >= 50 ? 1 : 0) + << (LangOpts.OpenMP >= 50 ? 1 : 0) << RefExpr->getSourceRange(); + continue; + } + } + ExprResult Res; { Sema::TentativeAnalysisScope Trap(*this); diff --git a/clang/test/OpenMP/depend_template_subscription.cpp b/clang/test/OpenMP/depend_template_subscription.cpp new file mode 100644 --- /dev/null +++ b/clang/test/OpenMP/depend_template_subscription.cpp @@ -0,0 +1,49 @@ +// RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s + +#ifndef HEADER +#define HEADER + +template +void test(double *A, IndexT k) +{ + #pragma omp task depend(out: A[k]) + { + ; + } +} +// CHECK: template void test(double *A, IndexT k) { +// CHECK: #pragma omp task depend(out : A[k]) +// CHECK: { +// CHECK: ; +// CHECK: } +// CHECK: } +// CHECK: template<> void test(double *A, int k) { +// CHECK: #pragma omp task depend(out : A[k]) +// CHECK: { +// CHECK: ; +// CHECK: } +// CHECK: } + + +struct lValueVector { + int operator [] (int index) { + return index + 42; + } +}; +template +void test2(BaseTypeT A, IndexT k) +{ + #pragma omp task depend(out: A[k]) // expected-error {{expected addressable lvalue expression, array element or array section}} + { + ; + } +} +int driver(double *A) +{ + int k = 42; + test(A, k); + test2(lValueVector(), k); // expected-note {{in instantiation of function template specialization 'test2' requested here}} + return 0; +} + +#endif \ No newline at end of file