Implement support for null non-type template arguments for non-type
template parameters of pointer, pointer-to-member, or nullptr_t
type in C++11. Fixes PR9700 / <rdar://problem/11193097>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154219 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/TemplateBase.cpp b/lib/AST/TemplateBase.cpp
index 7e6bae2..531e03e 100644
--- a/lib/AST/TemplateBase.cpp
+++ b/lib/AST/TemplateBase.cpp
@@ -80,9 +80,13 @@
return true;
case Declaration:
- if (DeclContext *DC = dyn_cast<DeclContext>(getAsDecl()))
- return DC->isDependentContext();
- return getAsDecl()->getDeclContext()->isDependentContext();
+ if (Decl *D = getAsDecl()) {
+ if (DeclContext *DC = dyn_cast<DeclContext>(D))
+ return DC->isDependentContext();
+ return D->getDeclContext()->isDependentContext();
+ }
+
+ return false;
case Integral:
// Never dependent
@@ -118,10 +122,13 @@
return true;
case Declaration:
- if (DeclContext *DC = dyn_cast<DeclContext>(getAsDecl()))
- return DC->isDependentContext();
- return getAsDecl()->getDeclContext()->isDependentContext();
-
+ if (Decl *D = getAsDecl()) {
+ if (DeclContext *DC = dyn_cast<DeclContext>(D))
+ return DC->isDependentContext();
+ return D->getDeclContext()->isDependentContext();
+ }
+ return false;
+
case Integral:
// Never dependent
return false;
@@ -322,16 +329,14 @@
}
case Declaration: {
- bool Unnamed = true;
if (NamedDecl *ND = dyn_cast_or_null<NamedDecl>(getAsDecl())) {
if (ND->getDeclName()) {
- Unnamed = false;
Out << *ND;
+ } else {
+ Out << "<anonymous>";
}
- }
-
- if (Unnamed) {
- Out << "<anonymous>";
+ } else {
+ Out << "nullptr";
}
break;
}
@@ -488,7 +493,9 @@
return DB << Arg.getAsType();
case TemplateArgument::Declaration:
- return DB << Arg.getAsDecl();
+ if (Decl *D = Arg.getAsDecl())
+ return DB << D;
+ return DB << "nullptr";
case TemplateArgument::Integral:
return DB << Arg.getAsIntegral()->toString(10);