Skip to content
This repository was archived by the owner on Aug 31, 2019. It is now read-only.

Commit bdbcfcb

Browse files
committed
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
1 parent fa0c754 commit bdbcfcb

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/AST/DeclPrinter.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,11 @@ void DeclPrinter::VisitLabelDecl(LabelDecl *D) {
715715

716716
void DeclPrinter::VisitVarDecl(VarDecl *D) {
717717
prettyPrintPragmas(D);
718+
719+
QualType T = D->getTypeSourceInfo()
720+
? D->getTypeSourceInfo()->getType()
721+
: D->getASTContext().getUnqualifiedObjCPointerType(D->getType());
722+
718723
if (!Policy.SuppressSpecifiers) {
719724
StorageClass SC = D->getStorageClass();
720725
if (SC != SC_None)
@@ -736,11 +741,13 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) {
736741

737742
if (D->isModulePrivate())
738743
Out << "__module_private__ ";
744+
745+
if (D->isConstexpr()) {
746+
Out << "constexpr ";
747+
T.removeLocalConst();
748+
}
739749
}
740750

741-
QualType T = D->getTypeSourceInfo()
742-
? D->getTypeSourceInfo()->getType()
743-
: D->getASTContext().getUnqualifiedObjCPointerType(D->getType());
744751
printDeclType(T, D->getName());
745752
Expr *Init = D->getInit();
746753
if (!Policy.SuppressInitializers && Init) {

test/SemaCXX/ast-print.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,13 @@ template <typename T> struct Foo : T {
228228
};
229229
}
230230

231-
namespace dont_crash {
231+
namespace dont_crash_on_auto_vars {
232232
struct T { enum E {X = 12ll }; };
233233
struct S {
234234
struct { int I; } ADecl;
235235
static const auto Y = T::X;
236236
};
237237
//CHECK: static const auto Y = T::X;
238+
constexpr auto var = T::X;
239+
//CHECK: constexpr auto var = T::X;
238240
}

0 commit comments

Comments
 (0)