[cfe-commits] r152401 - in /cfe/trunk: lib/AST/StmtPrinter.cpp test/SemaCXX/cxx11-ast-print.cpp

Richard Smith richard-llvm at metafoo.co.uk
Fri Mar 9 02:10:02 PST 2012


Author: rsmith
Date: Fri Mar  9 04:10:02 2012
New Revision: 152401

URL: http://llvm.org/viewvc/llvm-project?rev=152401&view=rev
Log:
Fix statement printing for raw and template user-defined literals.

Modified:
    cfe/trunk/lib/AST/StmtPrinter.cpp
    cfe/trunk/test/SemaCXX/cxx11-ast-print.cpp

Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=152401&r1=152400&r2=152401&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Fri Mar  9 04:10:02 2012
@@ -1225,14 +1225,17 @@
 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;

Modified: cfe/trunk/test/SemaCXX/cxx11-ast-print.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx11-ast-print.cpp?rev=152401&r1=152400&r2=152401&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx11-ast-print.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx11-ast-print.cpp Fri Mar  9 04:10:02 2012
@@ -10,6 +10,15 @@
 // 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 *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;





More information about the cfe-commits mailing list