[cfe-commits] [PATCH] Fix for assertion when solving unresolved templates

Magee, Josh Joshua.Magee at am.sony.com
Mon Aug 20 14:51:14 PDT 2012


Hi,

This is my first attempt at submitting a patch. :-)

The patch fixes an assertion that occurs when rewriting an UnresolvedLookupExpr
instance consisting of a call to a templated function with no explicit template
arguments.  In the regression test included with this patch, the function "bar"
is called without explicit template arguments.  While this is an error, it
should generate a diagnostic error message without triggering the assertion.

The assertion occurs because it is forbidden to call 'getNumTemplateArgs' and
'getTemplateArgs' on objects without explicit template arguments (as spelled
out in a comment in include/clang/AST/ExprCXX.h, right before
getExplicitTemplateArgs).  The fix is to guard the call to
TransformTemplateArguments so that it is only invoked if there really are
explicit template arguments.

Another possible solution would be to check for explicit template arguments
inside getNumTemplateArgs() and friends, which is actually how
corresponding/similar methods are implemented for DeclRefExpr in Expr.h.  Given
the comment mentioned above, it seems that this inconsistency is by design.
I'd be interested to know the motivation behind the difference in design.


Thank you!
Josh Magee
-------------- next part --------------
A non-text attachment was scrubbed...
Name: template-specialization-assertion.diff
Type: application/octet-stream
Size: 1595 bytes
Desc: template-specialization-assertion.diff
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120820/df854b4f/attachment.obj>


More information about the cfe-commits mailing list