From: Vassil Vassilev Date: Fri, 8 Jul 2016 21:09:08 +0000 (+0000) Subject: Teach -ast-print to print constexpr variables. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bdbcfcb4a760e7537d29b40bf2dd8b06f001369e;p=clang Teach -ast-print to print constexpr variables. Patch reviewed by Richard Smith (D22168). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@274930 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/DeclPrinter.cpp b/lib/AST/DeclPrinter.cpp index bfdb47b90d..7e786990be 100644 --- a/lib/AST/DeclPrinter.cpp +++ b/lib/AST/DeclPrinter.cpp @@ -715,6 +715,11 @@ void DeclPrinter::VisitLabelDecl(LabelDecl *D) { void DeclPrinter::VisitVarDecl(VarDecl *D) { prettyPrintPragmas(D); + + QualType T = D->getTypeSourceInfo() + ? D->getTypeSourceInfo()->getType() + : D->getASTContext().getUnqualifiedObjCPointerType(D->getType()); + if (!Policy.SuppressSpecifiers) { StorageClass SC = D->getStorageClass(); if (SC != SC_None) @@ -736,11 +741,13 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) { if (D->isModulePrivate()) Out << "__module_private__ "; + + if (D->isConstexpr()) { + Out << "constexpr "; + T.removeLocalConst(); + } } - QualType T = D->getTypeSourceInfo() - ? D->getTypeSourceInfo()->getType() - : D->getASTContext().getUnqualifiedObjCPointerType(D->getType()); printDeclType(T, D->getName()); Expr *Init = D->getInit(); if (!Policy.SuppressInitializers && Init) { diff --git a/test/SemaCXX/ast-print.cpp b/test/SemaCXX/ast-print.cpp index 733931803b..408af35c29 100644 --- a/test/SemaCXX/ast-print.cpp +++ b/test/SemaCXX/ast-print.cpp @@ -228,11 +228,13 @@ template struct Foo : T { }; } -namespace dont_crash { +namespace dont_crash_on_auto_vars { struct T { enum E {X = 12ll }; }; struct S { struct { int I; } ADecl; static const auto Y = T::X; }; //CHECK: static const auto Y = T::X; +constexpr auto var = T::X; +//CHECK: constexpr auto var = T::X; }