Skip to content

Commit

Permalink
Handle VarTemplateDecl in DeclContextPrinter
Browse files Browse the repository at this point in the history
This commit fixes a crash that occurs when -print-decl-contexts AST consumer
tries to print an unhandled declaration.

rdar://19467234

Differential Revision: https://reviews.llvm.org/D26964

llvm-svn: 290886
  • Loading branch information
hyp committed Jan 3, 2017
1 parent 21c3293 commit a186417
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 4 additions & 0 deletions clang/lib/Frontend/ASTConsumers.cpp
Expand Up @@ -522,6 +522,10 @@ void DeclContextPrinter::PrintDeclContext(const DeclContext* DC,
Out << "<access specifier>\n";
break;
}
case Decl::VarTemplate: {
Out << "<var template> " << *cast<VarTemplateDecl>(I) << "\n";
break;
}
default:
Out << "DeclKind: " << DK << '"' << I << "\"\n";
llvm_unreachable("decl unhandled");
Expand Down
12 changes: 6 additions & 6 deletions clang/test/Coverage/ast-printing.cpp
@@ -1,9 +1,9 @@
// RUN: %clang_cc1 -fsyntax-only %s
// RUN: %clang_cc1 -ast-print %s -o %t.1.cpp
// RUN: %clang_cc1 -ast-print %t.1.cpp -o %t.2.cpp
// RUN: %clang_cc1 -std=c++14 -fsyntax-only %s
// RUN: %clang_cc1 -std=c++14 -ast-print %s -o %t.1.cpp
// RUN: %clang_cc1 -std=c++14 -ast-print %t.1.cpp -o %t.2.cpp
// RUN: diff %t.1.cpp %t.2.cpp
// RUN: %clang_cc1 -ast-dump %s
// RUN: %clang_cc1 -print-decl-contexts %s
// RUN: %clang_cc1 -fdump-record-layouts %s
// RUN: %clang_cc1 -std=c++14 -ast-dump %s
// RUN: %clang_cc1 -std=c++14 -print-decl-contexts %s
// RUN: %clang_cc1 -std=c++14 -fdump-record-layouts %s

#include "cxx-language-features.inc"
3 changes: 3 additions & 0 deletions clang/test/Coverage/cxx-language-features.inc
Expand Up @@ -60,3 +60,6 @@ struct ClassTemplatePartialSpecialization<T, true> { };
struct AccessSpec {
private:
};

// Variable template
template <typename T> T varTemplate = 0;

0 comments on commit a186417

Please sign in to comment.