diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2013-02-22 15:46:01 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2013-02-22 15:46:01 +0000 |
commit | 5eada844fa70b6e2bc941dd7306f7a4fb1e8529d (patch) | |
tree | e493a8ac86fbc8e41cbdcdddb70ac573e3e23e69 | |
parent | 6ebf09130479bc7605aa09a3e6c4dc2ba3513495 (diff) |
Streamify getNameForDiagnostic and remove the string versions of PrintTemplateArgumentList.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175894 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/Decl.h | 8 | ||||
-rw-r--r-- | include/clang/AST/DeclTemplate.h | 2 | ||||
-rw-r--r-- | include/clang/AST/Type.h | 18 | ||||
-rw-r--r-- | lib/AST/ASTContext.cpp | 6 | ||||
-rw-r--r-- | lib/AST/ASTDiagnostic.cpp | 8 | ||||
-rw-r--r-- | lib/AST/Decl.cpp | 25 | ||||
-rw-r--r-- | lib/AST/DeclTemplate.cpp | 14 | ||||
-rw-r--r-- | lib/AST/NestedNameSpecifier.cpp | 10 | ||||
-rw-r--r-- | lib/AST/StmtPrinter.cpp | 48 | ||||
-rw-r--r-- | lib/AST/TemplateBase.cpp | 4 | ||||
-rw-r--r-- | lib/AST/TypePrinter.cpp | 126 | ||||
-rw-r--r-- | lib/CodeGen/CGDebugInfo.cpp | 24 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateInstantiate.cpp | 16 | ||||
-rw-r--r-- | tools/libclang/CIndex.cpp | 4 | ||||
-rw-r--r-- | unittests/Tooling/RecursiveASTVisitorTest.cpp | 5 |
15 files changed, 77 insertions, 241 deletions
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index c10080366c..010563fdd9 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -169,13 +169,13 @@ public: /// specializations are printed with their template arguments. /// /// TODO: use an API that doesn't require so many temporary strings - virtual void getNameForDiagnostic(std::string &S, + virtual void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const { if (Qualified) - S += getQualifiedNameAsString(Policy); + OS << getQualifiedNameAsString(Policy); else - S += getNameAsString(); + printName(OS); } /// declarationReplaces - Determine whether this declaration, if @@ -1606,7 +1606,7 @@ public: return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); } - virtual void getNameForDiagnostic(std::string &S, + virtual void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const; diff --git a/include/clang/AST/DeclTemplate.h b/include/clang/AST/DeclTemplate.h index 4b109ac8f8..525a156a93 100644 --- a/include/clang/AST/DeclTemplate.h +++ b/include/clang/AST/DeclTemplate.h @@ -1432,7 +1432,7 @@ public: static ClassTemplateSpecializationDecl * CreateDeserialized(ASTContext &C, unsigned ID); - virtual void getNameForDiagnostic(std::string &S, + virtual void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const; diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index c6f8baa202..df285101e3 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -3012,9 +3012,6 @@ public: bool isSugared() const { return false; } QualType desugar() const { return QualType(this, 0); } - // FIXME: Remove the string version. - void printExceptionSpecification(std::string &S, - const PrintingPolicy &Policy) const; void printExceptionSpecification(raw_ostream &OS, const PrintingPolicy &Policy) const; @@ -3656,21 +3653,6 @@ public: /// \brief Print a template argument list, including the '<' and '>' /// enclosing the template arguments. - // FIXME: remove the string ones. - static std::string PrintTemplateArgumentList(const TemplateArgument *Args, - unsigned NumArgs, - const PrintingPolicy &Policy, - bool SkipBrackets = false); - - static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args, - unsigned NumArgs, - const PrintingPolicy &Policy); - - static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &, - const PrintingPolicy &Policy); - - /// \brief Print a template argument list, including the '<' and '>' - /// enclosing the template arguments. static void PrintTemplateArgumentList(raw_ostream &OS, const TemplateArgument *Args, unsigned NumArgs, diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 514c76e9f6..db1aa1a944 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -5142,13 +5142,11 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, if (ClassTemplateSpecializationDecl *Spec = dyn_cast<ClassTemplateSpecializationDecl>(RDecl)) { const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); - std::string TemplateArgsStr - = TemplateSpecializationType::PrintTemplateArgumentList( + llvm::raw_string_ostream OS(S); + TemplateSpecializationType::PrintTemplateArgumentList(OS, TemplateArgs.data(), TemplateArgs.size(), (*this).getPrintingPolicy()); - - S += TemplateArgsStr; } } else { S += '?'; diff --git a/lib/AST/ASTDiagnostic.cpp b/lib/AST/ASTDiagnostic.cpp index 6a950d8dfe..d956eeee17 100644 --- a/lib/AST/ASTDiagnostic.cpp +++ b/lib/AST/ASTDiagnostic.cpp @@ -313,7 +313,8 @@ void clang::FormatASTNodeDiagnosticArgument( Qualified = false; } const NamedDecl *ND = reinterpret_cast<const NamedDecl*>(Val); - ND->getNameForDiagnostic(S, Context.getPrintingPolicy(), Qualified); + llvm::raw_string_ostream OS(S); + ND->getNameForDiagnostic(OS, Context.getPrintingPolicy(), Qualified); break; } case DiagnosticsEngine::ak_nestednamespec: { @@ -348,7 +349,10 @@ void clang::FormatASTNodeDiagnosticArgument( S += "function "; S += "'"; - ND->getNameForDiagnostic(S, Context.getPrintingPolicy(), true); + { + llvm::raw_string_ostream OS(S); + ND->getNameForDiagnostic(OS, Context.getPrintingPolicy(), true); + } S += "'"; } NeedQuotes = false; diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 61b3be180b..0dbb0d30aa 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -1194,13 +1194,12 @@ std::string NamedDecl::getQualifiedNameAsString(const PrintingPolicy &P) const { I != E; ++I) { if (const ClassTemplateSpecializationDecl *Spec = dyn_cast<ClassTemplateSpecializationDecl>(*I)) { + OS << Spec->getName(); const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); - std::string TemplateArgsStr - = TemplateSpecializationType::PrintTemplateArgumentList( - TemplateArgs.data(), - TemplateArgs.size(), - P); - OS << Spec->getName() << TemplateArgsStr; + TemplateSpecializationType::PrintTemplateArgumentList(OS, + TemplateArgs.data(), + TemplateArgs.size(), + P); } else if (const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(*I)) { if (ND->isAnonymousNamespace()) OS << "<anonymous namespace>"; @@ -1953,17 +1952,13 @@ unsigned ParmVarDecl::getParameterIndexLarge() const { // FunctionDecl Implementation //===----------------------------------------------------------------------===// -void FunctionDecl::getNameForDiagnostic(std::string &S, - const PrintingPolicy &Policy, - bool Qualified) const { - NamedDecl::getNameForDiagnostic(S, Policy, Qualified); +void FunctionDecl::getNameForDiagnostic( + raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const { + NamedDecl::getNameForDiagnostic(OS, Policy, Qualified); const TemplateArgumentList *TemplateArgs = getTemplateSpecializationArgs(); if (TemplateArgs) - S += TemplateSpecializationType::PrintTemplateArgumentList( - TemplateArgs->data(), - TemplateArgs->size(), - Policy); - + TemplateSpecializationType::PrintTemplateArgumentList( + OS, TemplateArgs->data(), TemplateArgs->size(), Policy); } bool FunctionDecl::isVariadic() const { diff --git a/lib/AST/DeclTemplate.cpp b/lib/AST/DeclTemplate.cpp index 5e25536134..0b94f7d2c4 100644 --- a/lib/AST/DeclTemplate.cpp +++ b/lib/AST/DeclTemplate.cpp @@ -743,17 +743,13 @@ ClassTemplateSpecializationDecl::CreateDeserialized(ASTContext &C, return Result; } -void -ClassTemplateSpecializationDecl::getNameForDiagnostic(std::string &S, - const PrintingPolicy &Policy, - bool Qualified) const { - NamedDecl::getNameForDiagnostic(S, Policy, Qualified); +void ClassTemplateSpecializationDecl::getNameForDiagnostic( + raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const { + NamedDecl::getNameForDiagnostic(OS, Policy, Qualified); const TemplateArgumentList &TemplateArgs = getTemplateArgs(); - S += TemplateSpecializationType::PrintTemplateArgumentList( - TemplateArgs.data(), - TemplateArgs.size(), - Policy); + TemplateSpecializationType::PrintTemplateArgumentList( + OS, TemplateArgs.data(), TemplateArgs.size(), Policy); } ClassTemplateDecl * diff --git a/lib/AST/NestedNameSpecifier.cpp b/lib/AST/NestedNameSpecifier.cpp index 719df5984b..79cc21a062 100644 --- a/lib/AST/NestedNameSpecifier.cpp +++ b/lib/AST/NestedNameSpecifier.cpp @@ -249,7 +249,6 @@ NestedNameSpecifier::print(raw_ostream &OS, // Fall through to print the type. case TypeSpec: { - std::string TypeStr; const Type *T = getAsType(); PrintingPolicy InnerPolicy(Policy); @@ -271,15 +270,12 @@ NestedNameSpecifier::print(raw_ostream &OS, SpecType->getTemplateName().print(OS, InnerPolicy, true); // Print the template argument list. - TypeStr = TemplateSpecializationType::PrintTemplateArgumentList( - SpecType->getArgs(), - SpecType->getNumArgs(), - InnerPolicy); + TemplateSpecializationType::PrintTemplateArgumentList( + OS, SpecType->getArgs(), SpecType->getNumArgs(), InnerPolicy); } else { // Print the type normally - TypeStr = QualType(T, 0).getAsString(InnerPolicy); + QualType(T, 0).print(OS, InnerPolicy); } - OS << TypeStr; break; } } diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index 65e7c1b427..23506b5e26 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -586,10 +586,8 @@ void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) { OS << "template "; OS << Node->getNameInfo(); if (Node->hasExplicitTemplateArgs()) - OS << TemplateSpecializationType::PrintTemplateArgumentList( - Node->getTemplateArgs(), - Node->getNumTemplateArgs(), - Policy); + TemplateSpecializationType::PrintTemplateArgumentList( + OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy); } void StmtPrinter::VisitDependentScopeDeclRefExpr( @@ -600,10 +598,8 @@ void StmtPrinter::VisitDependentScopeDeclRefExpr( OS << "template "; OS << Node->getNameInfo(); if (Node->hasExplicitTemplateArgs()) - OS << TemplateSpecializationType::PrintTemplateArgumentList( - Node->getTemplateArgs(), - Node->getNumTemplateArgs(), - Policy); + TemplateSpecializationType::PrintTemplateArgumentList( + OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy); } void StmtPrinter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) { @@ -613,10 +609,8 @@ void StmtPrinter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) { OS << "template "; OS << Node->getNameInfo(); if (Node->hasExplicitTemplateArgs()) - OS << TemplateSpecializationType::PrintTemplateArgumentList( - Node->getTemplateArgs(), - Node->getNumTemplateArgs(), - Policy); + TemplateSpecializationType::PrintTemplateArgumentList( + OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy); } void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) { @@ -933,10 +927,8 @@ void StmtPrinter::VisitMemberExpr(MemberExpr *Node) { OS << "template "; OS << Node->getMemberNameInfo(); if (Node->hasExplicitTemplateArgs()) - OS << TemplateSpecializationType::PrintTemplateArgumentList( - Node->getTemplateArgs(), - Node->getNumTemplateArgs(), - Policy); + TemplateSpecializationType::PrintTemplateArgumentList( + OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy); } void StmtPrinter::VisitObjCIsaExpr(ObjCIsaExpr *Node) { PrintExpr(Node->getBase()); @@ -1405,11 +1397,7 @@ void StmtPrinter::VisitLambdaExpr(LambdaExpr *Node) { const FunctionProtoType *Proto = Method->getType()->getAs<FunctionProtoType>(); - { - std::string ExceptionSpec; - Proto->printExceptionSpecification(ExceptionSpec, Policy); - OS << ExceptionSpec; - } + Proto->printExceptionSpecification(OS, Policy); // FIXME: Attributes @@ -1547,12 +1535,9 @@ void StmtPrinter::VisitCXXDependentScopeMemberExpr( if (Node->hasTemplateKeyword()) OS << "template "; OS << Node->getMemberNameInfo(); - if (Node->hasExplicitTemplateArgs()) { - OS << TemplateSpecializationType::PrintTemplateArgumentList( - Node->getTemplateArgs(), - Node->getNumTemplateArgs(), - Policy); - } + if (Node->hasExplicitTemplateArgs()) + TemplateSpecializationType::PrintTemplateArgumentList( + OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy); } void StmtPrinter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *Node) { @@ -1565,12 +1550,9 @@ void StmtPrinter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *Node) { if (Node->hasTemplateKeyword()) OS << "template "; OS << Node->getMemberNameInfo(); - if (Node->hasExplicitTemplateArgs()) { - OS << TemplateSpecializationType::PrintTemplateArgumentList( - Node->getTemplateArgs(), - Node->getNumTemplateArgs(), - Policy); - } + if (Node->hasExplicitTemplateArgs()) + TemplateSpecializationType::PrintTemplateArgumentList( + OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy); } static const char *getTypeTraitName(UnaryTypeTrait UTT) { diff --git a/lib/AST/TemplateBase.cpp b/lib/AST/TemplateBase.cpp index 2b50681345..d68b95edb7 100644 --- a/lib/AST/TemplateBase.cpp +++ b/lib/AST/TemplateBase.cpp @@ -347,9 +347,7 @@ void TemplateArgument::print(const PrintingPolicy &Policy, case Type: { PrintingPolicy SubPolicy(Policy); SubPolicy.SuppressStrongLifetime = true; - std::string TypeStr; - getAsType().getAsStringInternal(TypeStr, SubPolicy); - Out << TypeStr; + getAsType().print(Out, SubPolicy); break; } diff --git a/lib/AST/TypePrinter.cpp b/lib/AST/TypePrinter.cpp index 11d4faf414..9d1717a220 100644 --- a/lib/AST/TypePrinter.cpp +++ b/lib/AST/TypePrinter.cpp @@ -1348,132 +1348,6 @@ PrintTemplateArgumentList(raw_ostream &OS, OS << '>'; } -void -FunctionProtoType::printExceptionSpecification(std::string &S, - const PrintingPolicy &Policy) - const { - - if (hasDynamicExceptionSpec()) { - S += " throw("; - if (getExceptionSpecType() == EST_MSAny) - S += "..."; - else - for (unsigned I = 0, N = getNumExceptions(); I != N; ++I) { - if (I) - S += ", "; - - S += getExceptionType(I).getAsString(Policy); - } - S += ")"; - } else if (isNoexceptExceptionSpec(getExceptionSpecType())) { - S += " noexcept"; - if (getExceptionSpecType() == EST_ComputedNoexcept) { - S += "("; - llvm::raw_string_ostream EOut(S); - getNoexceptExpr()->printPretty(EOut, 0, Policy); - EOut.flush(); - S += EOut.str(); - S += ")"; - } - } -} - -std::string TemplateSpecializationType:: - PrintTemplateArgumentList(const TemplateArgumentListInfo &Args, - const PrintingPolicy &Policy) { - return PrintTemplateArgumentList(Args.getArgumentArray(), - Args.size(), - Policy); -} - -std::string -TemplateSpecializationType::PrintTemplateArgumentList( - const TemplateArgument *Args, - unsigned NumArgs, - const PrintingPolicy &Policy, - bool SkipBrackets) { - std::string SpecString; - if (!SkipBrackets) - SpecString += '<'; - - for (unsigned Arg = 0; Arg < NumArgs; ++Arg) { - if (SpecString.size() > unsigned(!SkipBrackets)) - SpecString += ", "; - - // Print the argument into a string. - std::string ArgString; - if (Args[Arg].getKind() == TemplateArgument::Pack) { - ArgString = PrintTemplateArgumentList(Args[Arg].pack_begin(), - Args[Arg].pack_size(), - Policy, true); - } else { - llvm::raw_string_ostream ArgOut(ArgString); - Args[Arg].print(Policy, ArgOut); - } - - // If this is the first argument and its string representation - // begins with the global scope specifier ('::foo'), add a space - // to avoid printing the diagraph '<:'. - if (!Arg && !ArgString.empty() && ArgString[0] == ':') - SpecString += ' '; - - SpecString += ArgString; - } - - // If the last character of our string is '>', add another space to - // keep the two '>''s separate tokens. We don't *have* to do this in - // C++0x, but it's still good hygiene. - if (!SpecString.empty() && SpecString[SpecString.size() - 1] == '>') - SpecString += ' '; - - if (!SkipBrackets) - SpecString += '>'; - - return SpecString; -} - -// Sadly, repeat all that with TemplateArgLoc. -std::string TemplateSpecializationType:: -PrintTemplateArgumentList(const TemplateArgumentLoc *Args, unsigned NumArgs, - const PrintingPolicy &Policy) { - std::string SpecString; - SpecString += '<'; - for (unsigned Arg = 0; Arg < NumArgs; ++Arg) { - if (SpecString.size() > 1) - SpecString += ", "; - - // Print the argument into a string. - std::string ArgString; - if (Args[Arg].getArgument().getKind() == TemplateArgument::Pack) { - ArgString = PrintTemplateArgumentList( - Args[Arg].getArgument().pack_begin(), - Args[Arg].getArgument().pack_size(), - Policy, true); - } else { - llvm::raw_string_ostream ArgOut(ArgString); - Args[Arg].getArgument().print(Policy, ArgOut); - } - - // If this is the first argument and its string representation - // begins with the global scope specifier ('::foo'), add a space - // to avoid printing the diagraph '<:'. - if (!Arg && !ArgString.empty() && ArgString[0] == ':') - SpecString += ' '; - - SpecString += ArgString; - } - - // If the last character of our string is '>', add another space to - // keep the two '>''s separate tokens. We don't *have* to do this in - // C++0x, but it's still good hygiene. - if (SpecString[SpecString.size() - 1] == '>') - SpecString += ' '; - - SpecString += '>'; - - return SpecString; -} - void QualType::dump(const char *msg) const { if (msg) llvm::errs() << msg << ": "; diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 4bd0e779f4..235d15f15b 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -126,7 +126,9 @@ StringRef CGDebugInfo::getFunctionName(const FunctionDecl *FD) { return FII->getName(); // Otherwise construct human readable name for debug info. - std::string NS = FD->getNameAsString(); + SmallString<128> NS; + llvm::raw_svector_ostream OS(NS); + FD->printName(OS); // Add any template specialization args. if (Info) { @@ -134,15 +136,15 @@ StringRef CGDebugInfo::getFunctionName(const FunctionDecl *FD) { const TemplateArgument *Args = TArgs->data(); unsigned NumArgs = TArgs->size(); PrintingPolicy Policy(CGM.getLangOpts()); - NS += TemplateSpecializationType::PrintTemplateArgumentList(Args, - NumArgs, - Policy); + TemplateSpecializationType::PrintTemplateArgumentList(OS, Args, NumArgs, + Policy); } // Copy this name on the side and use its reference. - char *StrPtr = DebugInfoNames.Allocate<char>(NS.length()); - memcpy(StrPtr, NS.data(), NS.length()); - return StringRef(StrPtr, NS.length()); + OS.flush(); + char *StrPtr = DebugInfoNames.Allocate<char>(NS.size()); + memcpy(StrPtr, NS.data(), NS.size()); + return StringRef(StrPtr, NS.size()); } StringRef CGDebugInfo::getObjCMethodName(const ObjCMethodDecl *OMD) { @@ -199,8 +201,12 @@ CGDebugInfo::getClassName(const RecordDecl *RD) { } StringRef Name = RD->getIdentifier()->getName(); PrintingPolicy Policy(CGM.getLangOpts()); - std::string TemplateArgList = - TemplateSpecializationType::PrintTemplateArgumentList(Args, NumArgs, Policy); + SmallString<128> TemplateArgList; + { + llvm::raw_svector_ostream OS(TemplateArgList); + TemplateSpecializationType::PrintTemplateArgumentList(OS, Args, NumArgs, + Policy); + } // Copy this name on the side and use its reference. size_t Length = Name.size() + TemplateArgList.size(); diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index c8f03725b9..79e16f3942 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -492,14 +492,16 @@ void Sema::PrintInstantiationStack() { case ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation: { TemplateDecl *Template = cast<TemplateDecl>(Active->Entity); - std::string TemplateArgsStr - = TemplateSpecializationType::PrintTemplateArgumentList( + SmallVector<char, 128> TemplateArgsStr; + llvm::raw_svector_ostream OS(TemplateArgsStr); + Template->printName(OS); + TemplateSpecializationType::PrintTemplateArgumentList(OS, Active->TemplateArgs, Active->NumTemplateArgs, getPrintingPolicy()); Diags.Report(Active->PointOfInstantiation, diag::note_default_arg_instantiation_here) - << (Template->getNameAsString() + TemplateArgsStr) + << OS.str() << Active->InstantiationRange; break; } @@ -544,14 +546,16 @@ void Sema::PrintInstantiationStack() { ParmVarDecl *Param = cast<ParmVarDecl>(Active->Entity); FunctionDecl *FD = cast<FunctionDecl>(Param->getDeclContext()); - std::string TemplateArgsStr - = TemplateSpecializationType::PrintTemplateArgumentList( + SmallVector<char, 128> TemplateArgsStr; + llvm::raw_svector_ostream OS(TemplateArgsStr); + FD->printName(OS); + TemplateSpecializationType::PrintTemplateArgumentList(OS, Active->TemplateArgs, Active->NumTemplateArgs, getPrintingPolicy()); Diags.Report(Active->PointOfInstantiation, diag::note_default_function_arg_instantiation_here) - << (FD->getNameAsString() + TemplateArgsStr) + << OS.str() << Active->InstantiationRange; break; } diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 3d81660b4d..563cc512d8 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -3422,10 +3422,10 @@ CXString clang_getCursorDisplayName(CXCursor C) { if (TypeSourceInfo *TSInfo = ClassSpec->getTypeAsWritten()) return cxstring::createDup(TSInfo->getType().getAsString(Policy)); - SmallString<64> Str; + SmallString<128> Str; llvm::raw_svector_ostream OS(Str); OS << *ClassSpec; - OS << TemplateSpecializationType::PrintTemplateArgumentList( + TemplateSpecializationType::PrintTemplateArgumentList(OS, ClassSpec->getTemplateArgs().data(), ClassSpec->getTemplateArgs().size(), Policy); diff --git a/unittests/Tooling/RecursiveASTVisitorTest.cpp b/unittests/Tooling/RecursiveASTVisitorTest.cpp index a68a869bf5..81be19003b 100644 --- a/unittests/Tooling/RecursiveASTVisitorTest.cpp +++ b/unittests/Tooling/RecursiveASTVisitorTest.cpp @@ -50,10 +50,11 @@ class NamedDeclVisitor public: bool VisitNamedDecl(NamedDecl *Decl) { std::string NameWithTemplateArgs; - Decl->getNameForDiagnostic(NameWithTemplateArgs, + llvm::raw_string_ostream OS(NameWithTemplateArgs); + Decl->getNameForDiagnostic(OS, Decl->getASTContext().getPrintingPolicy(), true); - Match(NameWithTemplateArgs, Decl->getLocation()); + Match(OS.str(), Decl->getLocation()); return true; } }; |