[PATCH] Fix PR19169:Crash on invalid attempting to specialize a template method as a template variable

Richard Smith richard at metafoo.co.uk
Fri Apr 18 14:23:00 PDT 2014


  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.)


================
Comment at: include/clang/Basic/DiagnosticSemaKinds.td:3300
@@ -3298,1 +3299,3 @@
+  "no variable template matches%select{| partial}0 specialization; "
+  "did you mean to use %1 as function template instead">;
   
----------------
`"did you mean"` diagnostics usually have a `?` at the end.

================
Comment at: lib/Sema/SemaTemplate.cpp:2384-2386
@@ +2383,5 @@
+      if (I != IEnd) {
+        return Diag(D.getIdentifierLoc(), diag::err_var_spec_no_template_but_method)
+                 << IsPartialSpecialization
+                 << (*I)->getDeclName();
+      }
----------------
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.

================
Comment at: include/clang/Basic/DiagnosticSemaKinds.td:3299
@@ +3298,3 @@
+def err_var_spec_no_template_but_method : Error<
+  "no variable template matches%select{| partial}0 specialization; "
+  "did you mean to use %1 as function template instead">;
----------------
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.


http://reviews.llvm.org/D3198






More information about the cfe-commits mailing list