Pretty print support for template arg enum constants

llvm-svn: 224184
This commit is contained in:
Will Wilson 2014-12-13 04:31:07 +00:00
parent 01ad4ae72b
commit 67c41ba0dd
3 changed files with 38 additions and 3 deletions

View File

@ -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<EnumType>()) {
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;
}

View File

@ -143,7 +143,7 @@ template <PR9412_MatchType type> int PR9412_t() {
} // expected-warning {{control reaches end of non-void function}}
void PR9412_f() {
PR9412_t<PR9412_Exact>(); // expected-note {{in instantiation of function template specialization 'PR9412_t<0>' requested here}}
PR9412_t<PR9412_Exact>(); // expected-note {{in instantiation of function template specialization 'PR9412_t<PR9412_MatchType::PR9412_Exact>' requested here}}
}
struct NoReturn {

View File

@ -0,0 +1,24 @@
// RUN: %clang_cc1 -fsyntax-only -ast-print %s | FileCheck %s
namespace NamedEnumNS
{
enum NamedEnum
{
Val0,
Val1
};
template <NamedEnum E>
void foo();
void test() {
// CHECK: template <NamedEnumNS::NamedEnum E = NamedEnumNS::NamedEnum::Val0>
NamedEnumNS::foo<Val0>();
// CHECK: template <NamedEnumNS::NamedEnum E = NamedEnumNS::NamedEnum::Val1>
NamedEnumNS::foo<(NamedEnum)1>();
// CHECK: template <NamedEnumNS::NamedEnum E = 2>
NamedEnumNS::foo<(NamedEnum)2>();
}
} // NamedEnumNS