[PATCH] PR10405 Missing actual type (aka) in error message when using decltype as a template parameter

Richard Smith richard at metafoo.co.uk
Thu May 29 19:12:56 PDT 2014


Here's one way to get a diagnostic with a `FunctionType` in it:

  void (&f)(decltype(1+1)) = 0;

This gives:

> <stdin>:1:8: error: non-const lvalue reference to type 'void (decltype(1 + 1))' cannot bind to a temporary of type 'int'

================
Comment at: lib/AST/ASTDiagnostic.cpp:68-69
@@ -67,3 +67,4 @@
 
-    // Don't desugar template specializations, unless it's an alias template.
+    // Don't desugar template specializations, unless it's an alias template
+    // or decltype appears anywhere in the type.
     if (const TemplateSpecializationType *TST
----------------
Better would be something like "Desugar template specializations if any template argument should be desugared."

================
Comment at: lib/AST/ASTDiagnostic.cpp:70-81
@@ -69,5 +69,14 @@
+    // or decltype appears anywhere in the type.
     if (const TemplateSpecializationType *TST
-          = dyn_cast<TemplateSpecializationType>(Ty))
-      if (!TST->isTypeAlias())
+        = dyn_cast<TemplateSpecializationType>(Ty)) {
+      for (auto Arg : *TST) {
+          if (Arg.getKind() == TemplateArgument::Type)
+              Desugar(Context, Arg.getAsType(), ShouldAKA);
+          if (ShouldAKA)
+              break;
+      }
+
+      if (!ShouldAKA && !TST->isTypeAlias())
         break;
+    }
 
----------------
It'd be better here to rebuild a TemplateSpecializationType that has the desugared template arguments in it.

================
Comment at: lib/AST/ASTDiagnostic.cpp:72
@@ +71,3 @@
+        = dyn_cast<TemplateSpecializationType>(Ty)) {
+      for (auto Arg : *TST) {
+          if (Arg.getKind() == TemplateArgument::Type)
----------------
Please don't use a `TemplateSpecializationType` as a container like this; it's not notionally a container of template arguments. Instead, add an `arguments` member function to `TemplateSpecializationType` to return the arguments list.

================
Comment at: lib/AST/ASTDiagnostic.cpp:73
@@ +72,3 @@
+      for (auto Arg : *TST) {
+          if (Arg.getKind() == TemplateArgument::Type)
+              Desugar(Context, Arg.getAsType(), ShouldAKA);
----------------
Please use 2-space indent, not 4.

http://reviews.llvm.org/D3588






More information about the cfe-commits mailing list