[PATCH] D110216: [clang] retain type sugar in auto / template argument deduction

Vassil Vassilev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 3 10:28:51 PDT 2021


v.g.vassilev added a comment.

In D110216#3038826 <https://reviews.llvm.org/D110216#3038826>, @mizvekov wrote:

> In D110216#3038797 <https://reviews.llvm.org/D110216#3038797>, @v.g.vassilev wrote:
>
>> Over the years we had some interest from people but never actually got implemented. Here <https://lists.llvm.org/pipermail/llvm-dev/2020-March/140054.html> were some ideas @rsmith and I discussed over the years. If that is helpful, let me know if I should dig a bit more into private email exchange.
>
> Sure, that is helpful :)
>
> There is other lower hanging fruit where we are losing sugar, and it would be a shame if we implemented this but then did not get much benefit from it because the sugar never got into the template argument in the first place.
>
> One such example is that we do not mark as 'elaborate' types which are written bare, without any scope specifiers.
>
> So for example in a case like this:
>
>   namespace foo {
>     struct Foo {};
>     Foo x = 0;
>   };
>
> We would still diagnose that assignment with the type of the variable printed as 'foo::Foo' instead of just 'Foo', as it was written, because the parser will have produced a type that is not wrapped in an ElaboratedType (or perhaps some other cheaper mechanism).

Handling that case is nice. I am more interested in retaining the sugar in template instantiations as it is essential for an optimization in our I/O system which uses clang as a library. If implement the instantiation diagnostic we can get rid of several hacky patches: https://github.com/vgvassilev/clang/commit/d87e2bbc8a266e295ee5a2065f1e587b325d4284 https://github.com/vgvassilev/clang/commit/fcc492fcab14e8b8dc156688dda6f237a04563a7 and https://github.com/vgvassilev/clang/commit/fe17b953325530267643f3391bfd59ac1519ef39



================
Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:1414
       TDF &= ~TDF_TopLevelParameterTypeList;
-      if (isForwardingReference(Param, 0) && Arg->isLValueReferenceType())
-        Param = Param->getPointeeType();
+      if (isForwardingReference(P, 0) && A->isLValueReferenceType())
+        P = P->getPointeeType();
----------------



================
Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:1777
               S, TemplateParams, NTTP, Noexcept, S.Context.BoolTy,
-              /*ArrayBound*/true, Info, Deduced);
+              /*ArrayBound*/ true, Info, Deduced);
 
----------------



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110216/new/

https://reviews.llvm.org/D110216



More information about the cfe-commits mailing list