]> granicus.if.org Git - clang/commitdiff
Fix statement printing for raw and template user-defined literals.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 9 Mar 2012 10:10:02 +0000 (10:10 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 9 Mar 2012 10:10:02 +0000 (10:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152401 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/StmtPrinter.cpp
test/SemaCXX/cxx11-ast-print.cpp

index d2233e094bb51320b4ecbc68cca6b0e45f08ff66..d5e53a69d44a0a584fa0918d63ad27404aa6c389 100644 (file)
@@ -1225,14 +1225,17 @@ void StmtPrinter::VisitCXXUuidofExpr(CXXUuidofExpr *Node) {
 void StmtPrinter::VisitUserDefinedLiteral(UserDefinedLiteral *Node) {
   switch (Node->getLiteralOperatorKind()) {
   case UserDefinedLiteral::LOK_Raw:
-    OS << cast<StringLiteral>(Node->getArg(0))->getString();
+    OS << cast<StringLiteral>(Node->getArg(0)->IgnoreImpCasts())->getString();
     break;
   case UserDefinedLiteral::LOK_Template: {
-    DeclRefExpr *DRE = cast<DeclRefExpr>(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<DeclRefExpr>(Node->getCallee()->IgnoreImpCasts());
+    const TemplateArgumentList *Args =
+      cast<FunctionDecl>(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;
index 33684ceb4c5f8bf3cb766a0763bb3b39325ad16c..afabf88bd5a7948e24b47571c570500d0832b699 100644 (file)
@@ -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 <char...> const char *operator "" _fritz();
+template<char...> 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;