From: Sam Weinig Date: Mon, 28 Dec 2009 03:19:38 +0000 (+0000) Subject: Fix for PR5871. Make __PRETTY_FUNCTION__ work for member functions defined in a class... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3521d01aed2f55b66c7ce2ad47541a9974079699;p=clang Fix for PR5871. Make __PRETTY_FUNCTION__ work for member functions defined in a class local to a function. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92200 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 220b0fb1c7..02a26d49f0 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -455,11 +455,6 @@ std::string NamedDecl::getQualifiedNameAsString(const PrintingPolicy &P) const { return getNameAsString(); while (Ctx) { - if (Ctx->isFunctionOrMethod()) - // FIXME: That probably will happen, when D was member of local - // scope class/struct/union. How do we handle this case? - break; - if (const ClassTemplateSpecializationDecl *Spec = dyn_cast(Ctx)) { const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); @@ -483,6 +478,34 @@ std::string NamedDecl::getQualifiedNameAsString(const PrintingPolicy &P) const { } else { Names.push_back(RD->getNameAsString()); } + } else if (const FunctionDecl *FD = dyn_cast(Ctx)) { + std::string Proto = FD->getNameAsString(); + + const FunctionProtoType *FT = 0; + if (FD->hasWrittenPrototype()) + FT = dyn_cast(FD->getType()->getAs()); + + Proto += "("; + if (FT) { + llvm::raw_string_ostream POut(Proto); + unsigned NumParams = FD->getNumParams(); + for (unsigned i = 0; i < NumParams; ++i) { + if (i) + POut << ", "; + std::string Param; + FD->getParamDecl(i)->getType().getAsStringInternal(Param, P); + POut << Param; + } + + if (FT->isVariadic()) { + if (NumParams > 0) + POut << ", "; + POut << "..."; + } + } + Proto += ")"; + + Names.push_back(Proto); } else if (const NamedDecl *ND = dyn_cast(Ctx)) Names.push_back(ND->getNameAsString()); else diff --git a/test/CodeGenCXX/predefined-expr.cpp b/test/CodeGenCXX/predefined-expr.cpp index e726adb163..f5e5ca9528 100644 --- a/test/CodeGenCXX/predefined-expr.cpp +++ b/test/CodeGenCXX/predefined-expr.cpp @@ -75,6 +75,9 @@ // CHECK: private constant [27 x i8] c"anonymousNamespaceFunction\00" // CHECK: private constant [84 x i8] c"void ::ClassInAnonymousNamespace::anonymousNamespaceFunction()\00" +// CHECK: private constant [19 x i8] c"localClassFunction\00" +// CHECK: private constant [59 x i8] c"void NS::localClass(int)::LocalClass::localClassFunction()\00" + int printf(const char * _Format, ...); class ClassInTopLevelNamespace { @@ -270,6 +273,19 @@ public: } anonymousUnion; }; +void localClass(int) { + class LocalClass { + public: + void localClassFunction() { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } + }; + LocalClass lc; + lc.localClassFunction(); +} + extern void externFunction() { printf("__func__ %s\n", __func__); printf("__FUNCTION__ %s\n", __FUNCTION__); @@ -325,6 +341,8 @@ int main() { anonymous.anonymousStruct.anonymousStructFunction(); anonymous.anonymousUnion.anonymousUnionFunction(); + NS::localClass(0); + NS::externFunction(); return 0;