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

Nikola Smiljanić popizdeh at gmail.com
Mon Jul 14 18:36:57 PDT 2014


================
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;
+    }
 
----------------
Richard Smith wrote:
> Nikola Smiljanić wrote:
> > Richard Smith wrote:
> > > It'd be better here to rebuild a TemplateSpecializationType that has the desugared template arguments in it.
> > What exactly do you mean by **rebuild**?
> I mean, ask the ASTContext to create a new TemplateSpecializationType with the desugared template arguments.
I thought it'd be obvious why I was doing this after I did it but I guess I should have asked. At first I though this was an optimization, create this QualType now as it will certainly be created later on. But I've noticed that getting the canonical type from sugared type returns  a different type object with same 'spelling'. I know that we're supposed to have only one QualType per type and I'm lost... Is this what you had in mind, and more importantly why?


```
    if (const TemplateSpecializationType *TST =
            dyn_cast<TemplateSpecializationType>(Ty)) {
      SmallVector<TemplateArgument, 4> Args;
      for (TemplateSpecializationType::iterator I = TST->args_begin(),
                                                E = TST->args_end();
           I != E; ++I) {
        if (I->getKind() == TemplateArgument::Type)
          Args.push_back(Desugar(Context, I->getAsType(), ShouldAKA));
        else
          Args.push_back(*I);
      }

      if (ShouldAKA || TST->isTypeAlias()) {
        QT = Context.getTemplateSpecializationType(
            TST->getTemplateName(), Args.data(), Args.size(), QT);
        break;
      }
    }
```

http://reviews.llvm.org/D3588






More information about the cfe-commits mailing list