[PATCH] [Review Request] PR15466 - clang accepts incorrect explicit instantiation

Serge Pavlov sepavloff at gmail.com
Fri May 3 11:27:05 PDT 2013


2013/5/1 Richard Smith <richard at metafoo.co.uk>

>
>
> ================
> Comment at: include/clang/Basic/DiagnosticParseKinds.td:592
> @@ -591,2 +591,3 @@
>  def err_expected_template_parameter : Error<"expected template
> parameter">;
> +def err_missed_templ_params : Error<"template parameter list is missed">;
>
> ----------------
> Maybe "missing template parameter list in %select{class|struct|union}0
> template definition", and rename to something like
> err_template_missing_parameters. But... if the 'template' keyword is just
> spurious here, this might still be confusing. Maybe we should just say
> "unexpected 'template' keyword before %select{class|struct|union}0
> definition"?
>

It looks like the message "missing template parameter list in ..." is a bit
more user-friendly. The message "unexpected 'template' keyword..." could be
confusing for unexperienced user.


>
> ================
> Comment at: lib/Parse/ParseDeclCXX.cpp:1541-1542
> @@ -1539,1 +1540,4 @@
> +             TUK == Sema::TUK_Definition) {
> +    if (!TemplateParams)
> +      Diag (TemplateInfo.TemplateLoc, diag::err_missed_templ_params);
>    } else {
> ----------------
> Is it possible for TemplateParams to be non-null for an
> ExplicitInstantiation?
>

TemplateParams is set up when a token of kind tok::annot_template_id is
found. It must not be null, otherwise it would mean that information on
template being instantiating is unavailable.


>
> If we expect this to happen due to a missing template parameter list,
> we're not going to recover very well here -- the class body is going to
> have a bunch of undeclared identifiers in it, and later uses of the class
> template are going to hit parse errors, because we won't treat the class
> name as a template name.
>

Some extent of recovering is useful however. Currently clang parses class
body even in template-parameter-list has errors. So parsing the body may be
useful also in the case of absent parameters.


-- 
Thanks,
--Serge
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130504/24507a9d/attachment.html>


More information about the cfe-commits mailing list