diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 5b5b1b685e153..6d5cb0fcaea24 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -7246,7 +7246,9 @@ void SemaOpenMP::ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope( FunctionDecl *UDecl = nullptr; if (IsTemplated && isa(CandidateDecl)) { auto *FTD = cast(CandidateDecl); - if (FTD->getTemplateParameters()->size() == TemplateParamLists.size()) + // FIXME: Should this compare the template parameter lists on all levels? + if (SemaRef.Context.isSameTemplateParameterList( + FTD->getTemplateParameters(), TemplateParamLists.back())) UDecl = FTD->getTemplatedDecl(); } else if (!IsTemplated) UDecl = dyn_cast(CandidateDecl); diff --git a/clang/test/SemaOpenMP/openmp-begin-declare-variant_template.cpp b/clang/test/SemaOpenMP/openmp-begin-declare-variant_template.cpp new file mode 100644 index 0000000000000..ded8f58253540 --- /dev/null +++ b/clang/test/SemaOpenMP/openmp-begin-declare-variant_template.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -triple x86_64 -fopenmp -verify %s + +// FIXME: Is this supposed to work? + +#pragma omp begin declare variant match(implementation={extension(allow_templates)}) +template void f(T) {} +// expected-note@-1 {{explicit instantiation refers here}} +#pragma end +template struct A {}; +template A f() = delete; +template void f(float); +// expected-error@-1 {{explicit instantiation of undefined function template 'f'}}