[PATCH] Fix PR19169:Crash on invalid attempting to specialize a template method as a template variable
Nick Lewycky
nlewycky at google.com
Wed Mar 26 23:23:12 PDT 2014
On 26 March 2014 23:10, Karthik Bhat <kv.bhat at samsung.com> wrote:
> 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?
>
Looks right to me. In particular, this is what the equivalent code in
ActOnClassTemplateSpecialization does.
The diagnostic is a little sub-par. In real-world cases that this has shown
up, the intention was not to use variable templates at all, but instead
missing parentheses in a call. Such a diagnostic would be even better.
Nick
>
> 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;
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140326/65104a7d/attachment.html>
More information about the llvm-commits
mailing list