This is an archive of the discontinued LLVM Phabricator instance.

Fix PR19169:Crash on invalid attempting to specialize a template method as a template variable
ClosedPublic

Authored by karthikthecool on Mar 26 2014, 11:10 PM.

Details

Summary

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

Diff Detail

Event Timeline

karthikthecool updated this revision to Unknown Object (????).Mar 27 2014, 2:13 AM

Hi Nick,
Modified the diagnostics in this case to make it more intutive as per your comments. Does this seems reasonable?
Thanks and Regards
Karthik Bhat

Hi Nick, Richard,
A gintle ping. Can i go ahead and commit this patch?
Thanks
Karthik Bhat

karthikthecool added a subscriber: Unknown Object (MLST).Apr 1 2014, 4:25 AM

Incorrectly added llvm-commits in cc. Move patch review to cfe commit mailing list.

Thanks
Karthik Bhat

ping..

Thanks
Karthik Bhat

Gentle ping..
Thanks

Sorry for the delay! The crash fix LGTM, but the diagnostic improvement needs refinement.

Ideally, I'd like for us to also give a note pointing at the template declaration in the case where we have a TemplateDecl that's not a VarTemplateDecl, and to give notes pointing at each function template in the case where we have a function template rather than a variable template, but I'm happy for this patch to be committed without that.

(Also, it'd be awesome if we could give a fixit adding the parens to the template declaration in either the case where there's only one element in the overload set or where we can figure out which one the user meant somehow.)

include/clang/Basic/DiagnosticSemaKinds.td
3318

The partial specialization case here makes no sense; you can't partially specialize a function template, so we know the user didn't mean that.

3319

"did you mean" diagnostics usually have a ? at the end.

lib/Sema/SemaTemplate.cpp
2429–2431

We should give this diagnostic in the case where there's only one declaration that's a function as well as in the case where there's an overload set of them.

karthikthecool updated this revision to Unknown Object (????).Apr 21 2014, 6:42 AM

Hi Richard,
Thanks a lot for your valuable inputs. Modified the diagnostic as per comments. I will try to address adding fixit for these cases in later revisions.
For now does this look good to commit?
Thanks again for spending your time on this i really appreciate your help.
Regards
Karthik Bhat

gentle ping..

Thanks
Karthik Bhat

Hi Richard,
a gentle ping.. would like to know if this patch is good to commit.
Thanks
Karthik Bhat

rsmith added inline comments.May 6 2014, 2:08 PM
lib/Sema/SemaTemplate.cpp
2432

Please fold the two cases together:

NamedDecl *FnTemplate;
if (auto *OTS = Name.getAsOverloadedTemplate())
  FnTemplate = *OTS->begin();
else
  FnTemplate = dyn_cast_or_null<FunctionTemplateDecl>(Name.getAsTemplateDecl());
if (FnTemplate)
  // ...
2433–2435

This check seems unnecessary; if we have an overloaded template name then by definition there are two or more function templates in the storage.

karthikthecool edited edge metadata.May 7 2014, 9:56 PM
karthikthecool removed a subscriber: Unknown Object (MLST).
karthikthecool edited edge metadata.

Thanks Richard for the review. Updating the patch as per review comments.

rsmith accepted this revision.May 8 2014, 1:54 AM
rsmith edited edge metadata.

LGTM, thanks!

This revision is now accepted and ready to land.May 8 2014, 1:54 AM
karthikthecool closed this revision.May 8 2014, 6:25 AM

Thanks Richard for the review. Committed as r208313.