[PATCH] FIXME fix: improving diagnostics for template arguments deduction of class templates and explicit specializations

Richard Smith richard at metafoo.co.uk
Wed Jul 17 17:35:03 PDT 2013



================
Comment at: lib/Sema/SemaOverload.cpp:551
@@ -550,3 +550,3 @@
 namespace {
-  // Structure used by OverloadCandidate::DeductionFailureInfo to store
+// Structure used by DeductionFailureInfo to store
   // template argument information.
----------------
More indentation please.

================
Comment at: lib/Sema/SemaTemplateDeduction.cpp:4152-4153
@@ -4151,3 +4151,4 @@
 ///
 /// \todo FIXME: Consider passing in the "also-ran" candidates that failed
 /// template argument deduction.
+UnresolvedSetIterator Sema::getMostSpecialized(
----------------
Remove this FIXME now that you've fixed it :)

================
Comment at: lib/Sema/SemaOverload.cpp:8510-8512
@@ +8509,5 @@
+// For Fn->getDescribedTemplate()
+    void DiagnoseBadDeduction(Sema &S, TemplatedDecl *Templated,
+                              DeductionFailureInfo &DeductionFailure,
+                              unsigned NumArgs) {
+  TemplateParameter Param = DeductionFailure.getTemplateParameter();
----------------
Less indentation please.

================
Comment at: lib/Sema/SemaOverload.cpp:8440
@@ +8439,3 @@
+void DiagnoseArityMismatch(Sema &S, TemplatedDecl *Fn,
+                               unsigned NumFormalArgs) {
+  llvm_unreachable(
----------------
Less indentation please.

================
Comment at: lib/Sema/SemaOverload.cpp:8411
@@ -8416,6 +8410,3 @@
 
-void DiagnoseArityMismatch(Sema &S, OverloadCandidate *Cand,
-                           unsigned NumFormalArgs) {
-  // TODO: treat calls to a missing default constructor as a special case
-
+bool CheckArityMismatch(Sema &S, OverloadCandidate *Cand, unsigned NumArgs) {
   FunctionDecl *Fn = Cand->Function;
----------------
Please add a comment to this function explaining what it's form

================
Comment at: lib/Sema/SemaOverload.cpp:8492-8496
@@ +8491,7 @@
+namespace {
+template <typename TemplatedDecl>
+TemplateDecl *getDescribedTemplate(TemplatedDecl *Templated) {
+  llvm_unreachable("Unsupported: Getting the described template declaration"
+                   " for bad deduction diagnosis");
+}
+
----------------
How are we guaranteed that this is not reached when diagnosing a bad deduction due to substitution failure in a TemplateSpecCandidateSet?

================
Comment at: lib/Sema/SemaOverload.cpp:8502-8504
@@ +8501,5 @@
+
+template <> TemplateDecl *getDescribedTemplate(CXXRecordDecl *Templated) {
+  return Templated->getDescribedClassTemplate();
+}
+}
----------------
It looks like this is unreachable: getDescribedTemplate is only used from DiagnoseBadDeduction, where TemplatedDecl is either FunctionDecl (for the overload set case) or Decl (for the template deduction case).

Maybe replace this function with one that takes a Decl*, and dispatches on whether it's a function/class?

================
Comment at: lib/Sema/SemaOverload.cpp:8447
@@ +8446,3 @@
+
+template <>
+void DiagnoseArityMismatch(Sema &S, FunctionDecl *Fn, unsigned NumFormalArgs) {
----------------
Maybe use three overloads for the OverloadCandidate*, FunctionDecl*, and Decl* cases, rather than an explicit specialization here? And perhaps fold the Decl* and FunctionDecl* cases together, with an assertion that the decl is in fact a FunctionDecl.


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



More information about the cfe-commits mailing list