Hi, The attached patch makes the following change: When instantiating function definitions set parameter names to those used in template.
The rationale is that we are copying the entire definition including parameter names which may differ between the declaration and the definition. This is particularly important if any parameters are unnamed in the declaration, as a DeclRef to an unnamed ParmVarDecl would cause the pretty printer to produce invalid output. This is also required by a tool I am building on top of Clang which requires template instantiations to be as well formed as standard declarations. Please let me know if OK to commit. Thanks, -- Peter
>From 92e1085c845019c67ad937c1d552fe4c0833b7ba Mon Sep 17 00:00:00 2001 From: Peter Collingbourne <[email protected]> Date: Sun, 18 Jul 2010 01:11:08 +0100 Subject: [PATCH] When instantiating function definitions set parameter names to those used in template The rationale is that we are copying the entire definition including parameter names which may differ between the declaration and the definition. This is particularly important if any parameters are unnamed in the declaration, as a DeclRef to an unnamed ParmVarDecl would cause the pretty printer to produce invalid output. --- lib/Sema/SemaTemplateInstantiateDecl.cpp | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 2fd3528..79b5532 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -2118,10 +2118,14 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, LocalInstantiationScope Scope(*this, MergeWithParentScope); // Introduce the instantiated function parameters into the local - // instantiation scope. - for (unsigned I = 0, N = PatternDecl->getNumParams(); I != N; ++I) - Scope.InstantiatedLocal(PatternDecl->getParamDecl(I), - Function->getParamDecl(I)); + // instantiation scope, and set the parameter names to those used + // in the template. + for (unsigned I = 0, N = PatternDecl->getNumParams(); I != N; ++I) { + const ParmVarDecl *PatternParam = PatternDecl->getParamDecl(I); + ParmVarDecl *FunctionParam = Function->getParamDecl(I); + FunctionParam->setDeclName(PatternParam->getDeclName()); + Scope.InstantiatedLocal(PatternParam, FunctionParam); + } // Enter the scope of this instantiation. We don't use // PushDeclContext because we don't have a scope. -- 1.7.1
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
