Teach -ast-print to print constexpr variables.

Patch reviewed by Richard Smith (D22168).

llvm-svn: 274930
This commit is contained in:
Vassil Vassilev 2016-07-08 21:09:08 +00:00
parent 5246482c7a
commit 1002373946
2 changed files with 13 additions and 4 deletions

View File

@ -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) {

View File

@ -228,11 +228,13 @@ template <typename T> 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;
}