diff options
author | Karthik Bhat <kv.bhat@samsung.com> | 2014-05-08 13:16:20 +0000 |
---|---|---|
committer | Karthik Bhat <kv.bhat@samsung.com> | 2014-05-08 13:16:20 +0000 |
commit | c52c190c1e790317e6448902fbf08511fb6c1789 (patch) | |
tree | 16e6e4821b1dd6695d4c1e7a5def183c336a5082 /lib/Sema/SemaTemplate.cpp | |
parent | 2d4fcb889809ede7c322081a15b4b088231589ff (diff) |
Fix PR19169 [Crash on invalid attempting to specialize a template method as a template variable].
A template declaration of a template name can be null in case we have a dependent name or a set of function templates.
Hence use dyn_cast_or_null instead of dyn_cast. Also improve the diagnostic emitted in this case.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208313 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplate.cpp')
-rw-r--r-- | lib/Sema/SemaTemplate.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index e21d1eef46..8c0261381c 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -2420,10 +2420,19 @@ DeclResult Sema::ActOnVarTemplateSpecialization( // The template-id must name a variable template. VarTemplateDecl *VarTemplate = - dyn_cast<VarTemplateDecl>(Name.getAsTemplateDecl()); - if (!VarTemplate) + dyn_cast_or_null<VarTemplateDecl>(Name.getAsTemplateDecl()); + if (!VarTemplate) { + NamedDecl *FnTemplate; + if (auto *OTS = Name.getAsOverloadedTemplate()) + FnTemplate = *OTS->begin(); + else + FnTemplate = dyn_cast_or_null<FunctionTemplateDecl>(Name.getAsTemplateDecl()); + if (FnTemplate) + return Diag(D.getIdentifierLoc(), diag::err_var_spec_no_template_but_method) + << FnTemplate->getDeclName(); return Diag(D.getIdentifierLoc(), diag::err_var_spec_no_template) << IsPartialSpecialization; + } // Check for unexpanded parameter packs in any of the template arguments. for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I) |