From: Richard Smith Date: Fri, 9 Mar 2012 10:10:02 +0000 (+0000) Subject: Fix statement printing for raw and template user-defined literals. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ef9f29804fa8932282a17b414ef0dde2ea4eec03;p=clang Fix statement printing for raw and template user-defined literals. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152401 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index d2233e094b..d5e53a69d4 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -1225,14 +1225,17 @@ void StmtPrinter::VisitCXXUuidofExpr(CXXUuidofExpr *Node) { void StmtPrinter::VisitUserDefinedLiteral(UserDefinedLiteral *Node) { switch (Node->getLiteralOperatorKind()) { case UserDefinedLiteral::LOK_Raw: - OS << cast(Node->getArg(0))->getString(); + OS << cast(Node->getArg(0)->IgnoreImpCasts())->getString(); break; case UserDefinedLiteral::LOK_Template: { - DeclRefExpr *DRE = cast(Node->getCallee()); - assert(DRE->hasExplicitTemplateArgs()); - const TemplateArgumentLoc *Args = DRE->getTemplateArgs(); - for (unsigned i = 0, e = DRE->getNumTemplateArgs(); i != e; ++i) { - char C = (char)Args[i].getArgument().getAsIntegral()->getZExtValue(); + DeclRefExpr *DRE = cast(Node->getCallee()->IgnoreImpCasts()); + const TemplateArgumentList *Args = + cast(DRE->getDecl())->getTemplateSpecializationArgs(); + assert(Args); + const TemplateArgument &Pack = Args->get(0); + for (TemplateArgument::pack_iterator I = Pack.pack_begin(), + E = Pack.pack_end(); I != E; ++I) { + char C = (char)I->getAsIntegral()->getZExtValue(); OS << C; } break; diff --git a/test/SemaCXX/cxx11-ast-print.cpp b/test/SemaCXX/cxx11-ast-print.cpp index 33684ceb4c..afabf88bd5 100644 --- a/test/SemaCXX/cxx11-ast-print.cpp +++ b/test/SemaCXX/cxx11-ast-print.cpp @@ -10,6 +10,15 @@ decltype(""_foo) operator"" _bar(unsigned long long); // CHECK: decltype(42_bar) operator "" _baz(long double); decltype(42_bar) operator"" _baz(long double); +// CHECK: decltype(4.5_baz) operator "" _baz(char); +decltype(4.5_baz) operator"" _baz(char); + +// CHECK: const char *operator "" _quux(const char *); +const char *operator"" _quux(const char *); + +// CHECK: template const char *operator "" _fritz(); +template const char *operator"" _fritz(); + // CHECK: const char *p1 = "bar1"_foo; const char *p1 = "bar1"_foo; // CHECK: const char *p2 = "bar2"_foo; @@ -20,3 +29,13 @@ const char *p3 = u8"bar3"_foo; const char *p4 = 0x129_bar; // CHECK: const char *p5 = 1.0E+12_baz; const char *p5 = 1e12_baz; +// CHECK: const char *p6 = 'x'_baz; +const char *p6 = 'x'_baz; +// CHECK: const char *p7 = 123_quux; +const char *p7 = 123_quux; +// CHECK: const char *p8 = 4.9_quux; +const char *p8 = 4.9_quux; +// CHECK: const char *p9 = 0x42e3F_fritz; +const char *p9 = 0x42e3F_fritz; +// CHECK: const char *p10 = 3.300e+15_fritz; +const char *p10 = 3.300e+15_fritz;