From: Sam Weinig Date: Sun, 27 Dec 2009 01:38:20 +0000 (+0000) Subject: Fix for PR5872. Add static specifier and const/volatile qualifiers to member function... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4eadcc569223135e13353c9381b448986e3f7053;p=clang Fix for PR5872. Add static specifier and const/volatile qualifiers to member functions in __PRETTY_FUNCTION__ predefined expressions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92171 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 960d83d103..a31a7f51f8 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -174,6 +174,8 @@ std::string PredefinedExpr::ComputeName(ASTContext &Context, IdentType IT, if (const CXXMethodDecl *MD = dyn_cast(FD)) { if (MD->isVirtual()) Out << "virtual "; + if (MD->isStatic()) + Out << "static "; } PrintingPolicy Policy(Context.getLangOptions()); @@ -203,6 +205,14 @@ std::string PredefinedExpr::ComputeName(ASTContext &Context, IdentType IT, } Proto += ")"; + if (const CXXMethodDecl *MD = dyn_cast(FD)) { + Qualifiers ThisQuals = Qualifiers::fromCVRMask(MD->getTypeQualifiers()); + if (ThisQuals.hasConst()) + Proto += " const"; + if (ThisQuals.hasVolatile()) + Proto += " volatile"; + } + if (!isa(FD) && !isa(FD)) AFT->getResultType().getAsStringInternal(Proto, Policy); diff --git a/test/CodeGenCXX/predefined-expr.cpp b/test/CodeGenCXX/predefined-expr.cpp index 92abcabbca..e726adb163 100644 --- a/test/CodeGenCXX/predefined-expr.cpp +++ b/test/CodeGenCXX/predefined-expr.cpp @@ -31,6 +31,15 @@ // CHECK: private constant [16 x i8] c"virtualFunction\00" // CHECK: private constant [44 x i8] c"virtual void NS::Derived::virtualFunction()\00" +// CHECK: private constant [22 x i8] c"constVolatileFunction\00" +// CHECK: private constant [54 x i8] c"void NS::Base::constVolatileFunction() const volatile\00" + +// CHECK: private constant [17 x i8] c"volatileFunction\00" +// CHECK: private constant [43 x i8] c"void NS::Base::volatileFunction() volatile\00" + +// CHECK: private constant [14 x i8] c"constFunction\00" +// CHECK: private constant [37 x i8] c"void NS::Base::constFunction() const\00" + // CHECK: private constant [26 x i8] c"functionReturingTemplate2\00" // CHECK: private constant [64 x i8] c"ClassTemplate NS::Base::functionReturingTemplate2()\00" @@ -57,8 +66,8 @@ // CHECK: private constant [15 x i8] c"inlineFunction\00" // CHECK: private constant [32 x i8] c"void NS::Base::inlineFunction()\00" -// CHECK: private constant [11 x i8] c"staticFunc\00" -// CHECK: private constant [28 x i8] c"void NS::Base::staticFunc()\00" +// CHECK: private constant [15 x i8] c"staticFunction\00" +// CHECK: private constant [39 x i8] c"static void NS::Base::staticFunction()\00" // CHECK: private constant [26 x i8] c"topLevelNamespaceFunction\00" // CHECK: private constant [59 x i8] c"void ClassInTopLevelNamespace::topLevelNamespaceFunction()\00" @@ -104,7 +113,7 @@ public: class Base { public: - static void staticFunc() { + static void staticFunction() { printf("__func__ %s\n", __func__); printf("__FUNCTION__ %s\n", __FUNCTION__); printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); @@ -173,6 +182,24 @@ public: printf("__FUNCTION__ %s\n", __FUNCTION__); printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); } + + void constFunction() const { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } + + void volatileFunction() volatile { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } + + void constVolatileFunction() const volatile { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } }; class Derived : public Base { @@ -258,7 +285,7 @@ int main() { ClassInTopLevelNamespace topLevelNamespace; topLevelNamespace.topLevelNamespaceFunction(); - NS::Base::staticFunc(); + NS::Base::staticFunction(); NS::Base b; b.inlineFunction(); @@ -273,7 +300,10 @@ int main() { b.functionReturingTemplate2(); b.functionTemplate1(0); b.functionTemplate1(0); - + b.constFunction(); + b.volatileFunction(); + b.constVolatileFunction(); + NS::Derived d; d.virtualFunction();