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

Serge Pavlov sepavloff at gmail.com
Fri Jun 21 12:35:50 PDT 2013


  The problem is already fixed in r184503.


================
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">;
 
----------------
Richard Smith wrote:
> 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 {
----------------
Richard Smith wrote:
> Is it possible for TemplateParams to be non-null for an ExplicitInstantiation?
> 
> 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.
TemplateParams is set up when a token of kind tok::annot_template_id is found. It must not be null, it would mean that information on template being instantiating is unavailable.

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.


http://llvm-reviews.chandlerc.com/D731



More information about the cfe-commits mailing list