saideepaksana wrote:

Hi Our main changes are in the file `SemaTemplate.cpp` and there are some 
changes from other people, which when we are trying to change, getting error's 
locally. So our main changes in the `SemaTemplate.cpp` are in the lines 8240 
only, 
```
bool 
Sema::CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams) {
  if (!S)
    return false;

  // Find the nearest enclosing declaration scope.
  S = S->getDeclParent();

  // C++ [temp.pre]p6: [P2096]
  //   A template, explicit specialization, or partial specialization shall not
  //   have C linkage.
  DeclContext *Ctx = S->getEntity();
  if (Ctx && Ctx->isExternCContext()) {
    SourceRange Range =
        TemplateParams->getTemplateLoc().isInvalid() && TemplateParams->size()
            ? TemplateParams->getParam(0)->getSourceRange()
            : TemplateParams->getSourceRange();
    Diag(Range.getBegin(), diag::err_template_linkage) << Range;
    if (const LinkageSpecDecl *LSD = Ctx->getExternCContext())
      Diag(LSD->getExternLoc(), diag::note_extern_c_begins_here);
    return true;
  }
  Ctx = Ctx ? Ctx->getRedeclContext() : nullptr;

  // Compute a SourceLocation to use for diagnostics. Prefer the explicit
  // template location, but fall back to nearby Decl locations when needed.
  SourceLocation Loc = TemplateParams->getTemplateLoc();
  if (Loc.isInvalid())
    Loc = TemplateParams->getSourceRange().getBegin();

  if (Loc.isInvalid() && Ctx) {
    if (const Decl *D = dyn_cast<Decl>(Ctx))
      Loc = D->getBeginLoc();
  }

  // Try to extract class context if present.
  CXXRecordDecl *RD = Ctx ? dyn_cast<CXXRecordDecl>(Ctx) : nullptr;
  if (Loc.isInvalid() && RD)
    Loc = RD->getLocation();

  if (Ctx) {
    if (Ctx->isFileContext())
      return false;

    if (RD) {
      // C++ [temp.mem]p2:
      //   A local class shall not have member templates.
      if (RD->isLocalClass()) {
        // when the template location is not valid we are trying to use 
fallback SourceLocation such that diagnostic prints a usable file:line:col 
location
        if (Loc.isInvalid())
          Loc = TemplateParams->getSourceRange().getBegin();

        return Diag(Loc, diag::err_template_inside_local_class)
                 << TemplateParams->getSourceRange();
      } 
      else {
        return false;
      }
    }
  }

  // when teplate declared outside the namspace or class scope it Fallbacks and 
it give valid SourceLocation with file:line info.
  if (Loc.isInvalid())
    Loc = TemplateParams->getSourceRange().getBegin();

  return Diag(Loc, diag::err_template_outside_namespace_or_class_scope)
           << TemplateParams->getSourceRange();
}
```



https://github.com/llvm/llvm-project/pull/167201
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to