diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -2576,6 +2576,8 @@ bool addClassTransitive(CXXRecordDecl *RD) { Classes.insert(RD); + if (InstantiationLoc.isInvalid()) + InstantiationLoc = RD->getLocation(); return ClassesTransitive.insert(RD); } 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 @@ -17549,6 +17549,7 @@ auto &DeclNames = SemaRef.getASTContext().DeclarationNames; MapperId.setName(DeclNames.getIdentifier( &SemaRef.getASTContext().Idents.get("default"))); + MapperId.setLoc(StartLoc); } // Iterators to find the current unresolved mapper expression. diff --git a/clang/test/OpenMP/template-specialization.cpp b/clang/test/OpenMP/template-specialization.cpp new file mode 100644 --- /dev/null +++ b/clang/test/OpenMP/template-specialization.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -verify -fopenmp -fsyntax-only %s + +// expected-no-diagnostics + +template +struct z { + static void aj() { + T f; +#pragma omp target map(f) + ; + } +}; + +template class ar {}; +template struct as {}; +template class z>>;