From 3b125546333bed63d11d8f09132f50f4710d109a Mon Sep 17 00:00:00 2001 From: Will Wilson Date: Sat, 13 Dec 2014 04:31:07 +0000 Subject: [PATCH] Pretty print support for template arg enum constants git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224184 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/TemplateBase.cpp | 15 ++++++++++-- test/SemaCXX/return-noreturn.cpp | 2 +- test/SemaTemplate/temp_arg_enum_printing.cpp | 24 ++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 test/SemaTemplate/temp_arg_enum_printing.cpp diff --git a/lib/AST/TemplateBase.cpp b/lib/AST/TemplateBase.cpp index f07b18e7c1..4250c813a2 100644 --- a/lib/AST/TemplateBase.cpp +++ b/lib/AST/TemplateBase.cpp @@ -33,11 +33,22 @@ using namespace clang; /// \param TemplArg the TemplateArgument instance to print. /// /// \param Out the raw_ostream instance to use for printing. +/// +/// \param Policy the printing policy for EnumConstantDecl printing. static void printIntegral(const TemplateArgument &TemplArg, - raw_ostream &Out) { + raw_ostream &Out, const PrintingPolicy& Policy) { const ::clang::Type *T = TemplArg.getIntegralType().getTypePtr(); const llvm::APSInt &Val = TemplArg.getAsIntegral(); + if (const EnumType* ET = T->getAs()) { + for (const EnumConstantDecl* ECD : ET->getDecl()->enumerators()) { + if (ECD->getInitVal() == Val) { + ECD->printQualifiedName(Out, Policy); + return; + } + } + } + if (T->isBooleanType()) { Out << (Val.getBoolValue() ? "true" : "false"); } else if (T->isCharType()) { @@ -378,7 +389,7 @@ void TemplateArgument::print(const PrintingPolicy &Policy, break; case Integral: { - printIntegral(*this, Out); + printIntegral(*this, Out, Policy); break; } diff --git a/test/SemaCXX/return-noreturn.cpp b/test/SemaCXX/return-noreturn.cpp index 61b45c5370..cdd96e6a9e 100644 --- a/test/SemaCXX/return-noreturn.cpp +++ b/test/SemaCXX/return-noreturn.cpp @@ -143,7 +143,7 @@ template int PR9412_t() { } // expected-warning {{control reaches end of non-void function}} void PR9412_f() { - PR9412_t(); // expected-note {{in instantiation of function template specialization 'PR9412_t<0>' requested here}} + PR9412_t(); // expected-note {{in instantiation of function template specialization 'PR9412_t' requested here}} } struct NoReturn { diff --git a/test/SemaTemplate/temp_arg_enum_printing.cpp b/test/SemaTemplate/temp_arg_enum_printing.cpp new file mode 100644 index 0000000000..a788975b20 --- /dev/null +++ b/test/SemaTemplate/temp_arg_enum_printing.cpp @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -fsyntax-only -ast-print %s | FileCheck %s + +namespace NamedEnumNS +{ + +enum NamedEnum +{ + Val0, + Val1 +}; + +template +void foo(); + +void test() { + // CHECK: template + NamedEnumNS::foo(); + // CHECK: template + NamedEnumNS::foo<(NamedEnum)1>(); + // CHECK: template + NamedEnumNS::foo<(NamedEnum)2>(); +} + +} // NamedEnumNS -- 2.40.0