[PATCH] Fix PR19169:Crash on invalid attempting to specialize a template method as a template variable
Karthik Bhat
kv.bhat at samsung.com
Wed Mar 26 23:10:15 PDT 2014
Hi rsmith, nicholas, aaron.ballman,
Hi All,
A small patch to fix PR19169. In ActOnVarTemplateSpecialization the getAsTemplateDecl() function might return null if template name refers to a set of function templates. Handle the same by using dynamic_cast_or_null instead of dynamic_cast which will crash if the pointer being casted is null.
Please let me know if i can go ahead and commit the same?
Thanks and Regards
Karthik Bhat
http://llvm-reviews.chandlerc.com/D3198
Files:
test/SemaCXX/cxx1y-variable-templates_top_level.cpp
lib/Sema/SemaTemplate.cpp
Index: test/SemaCXX/cxx1y-variable-templates_top_level.cpp
===================================================================
--- test/SemaCXX/cxx1y-variable-templates_top_level.cpp
+++ test/SemaCXX/cxx1y-variable-templates_top_level.cpp
@@ -448,3 +448,9 @@
static_assert(x<int> == 1, "");
#endif
}
+
+namespace PR19169 {
+ template <typename T> int* f();
+ template <typename T> void f();
+ template<> int f<double>; // expected-error {{no variable template matches specialization}}
+}
Index: lib/Sema/SemaTemplate.cpp
===================================================================
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -2375,7 +2375,7 @@
// The template-id must name a variable template.
VarTemplateDecl *VarTemplate =
- dyn_cast<VarTemplateDecl>(Name.getAsTemplateDecl());
+ dyn_cast_or_null<VarTemplateDecl>(Name.getAsTemplateDecl());
if (!VarTemplate)
return Diag(D.getIdentifierLoc(), diag::err_var_spec_no_template)
<< IsPartialSpecialization;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3198.1.patch
Type: text/x-patch
Size: 1030 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140326/1711aaaf/attachment.bin>
More information about the llvm-commits
mailing list