<div dir="ltr">Oh, now I see it. Missed this point in first reply.<div><br></div><div>Thanks!</div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-10-05 17:16 GMT-07:00 Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="">On 5 October 2017 at 14:55, Roman Popov via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thanks for response.<span><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px">However, having the ClassTemplatePartialSpecializa</span><span style="font-size:12.8px"><wbr>tionDecl (or, in the template-around-a-</span><span style="font-size:12.8px">ClassTemplat<wbr>eSpecializationDec</span><span style="font-size:12.8px">l case, the ClassTemplateSpecializationDec</span><span style="font-size:12.8px"><wbr>l) be a TypeDecl is actually a sensible and essentially necessary choice -- it represents the type of the "injected class name" within the template, that is, the (dependent) type of "*this" within the definition of the template and its members.</span></blockquote><div><br></div><div><br></div></span><div>But in this case ClassTemplateDecl should also be a TypeDecl? But it is not according to diagram:</div><div><a href="https://clang.llvm.org/doxygen/classclang_1_1ClassTemplateDecl.html#details" target="_blank">https://clang.llvm.org/doxygen<wbr>/classclang_1_1ClassTemplateDe<wbr>cl.html#details</a></div></div></blockquote><div><br></div></span><div>A ClassTemplateDecl is a wrapper around a CXXRecordDecl, which is a TypeDecl.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><div dir="ltr"><span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px">... we need to identify that A<T*> refers to the (dependent, not yet instantiated) class template partial specialization we're currently defining in order to look up X and determine that it's a type, which allows "A<T*>::X *y;" to be parsed as a declaration rather than as a multiplication expression.</span></blockquote><div><br></div></span><div>I understand. I don't yet looked into the parser code, so it was not evident for me that it influences AST type hierarchy.<br></div></div><div class="m_3264425322094247352HOEnZb"><div class="m_3264425322094247352h5"><div class="gmail_extra"><br><div class="gmail_quote">2017-10-05 14:02 GMT-07:00 Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span>On 5 October 2017 at 12:47, Roman Popov via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi all,<div><br></div><div>One thing that confused me in Clang AST is that ClassTemplatePartialSpeci<wbr>alizationDecl is derived from ClassTemplateSpecializati<wbr>onDecl, and thus is a TypeDecl. </div><div><br></div><div>What is the reasoning behind this decision?</div></div></blockquote><div><br></div></span><div>I think the original design idea was that a ClassTemplatePartialSpecializa<wbr>tionDecl is a templated form of ClassTemplateSpecializationDec<wbr>l (in the same way that a ClassTemplateDecl is a templated form of CXXRecordDecl etc.) That makes sense if you think about it -- a partial specialization is a template whose templated declaration is a specialization of a template. Only it's not quite implemented like that, because ClassTemplatePartialSpecializa<wbr>tionDecl isn't a template wrapper *around* a ClassTemplateSpecializationDec<wbr>l -- it's actually both a class and a template all at once.</div><div><br></div><div>This non-uniformity of template representation is quite awkward, and I think we know enough about how it works out now to consider it a minor design error.</div><div><br></div><div>However, having the ClassTemplatePartialSpecializa<wbr>tionDecl (or, in the template-around-a-ClassTemplat<wbr>eSpecializationDecl case, the ClassTemplateSpecializationDec<wbr>l) be a TypeDecl is actually a sensible and essentially necessary choice -- it represents the type of the "injected class name" within the template, that is, the (dependent) type of "*this" within the definition of the template and its members.</div><span><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I thought that partial specialization is still a template in C++, and only when it is fully specialized it becomes a real class.</div></div></blockquote><div><br></div></span><div>Yes, but correct semantic analysis of C++ templates requires modeling a family of dependent types too. Eg, within:</div><div><br></div><div>template<typename T> struct A;</div><div>template<typename T> struct A<T*> {</div><div> using X = int;</div><div> void f() {</div><div> A<T*>::X *y;</div><div> }</div><div>};</div><div><br></div><div>... we need to identify that A<T*> refers to the (dependent, not yet instantiated) class template partial specialization we're currently defining in order to look up X and determine that it's a type, which allows "A<T*>::X *y;" to be parsed as a declaration rather than as a multiplication expression.</div></div></div></div>
</blockquote></div><br></div>
</div></div><br></span>______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div></div>
</blockquote></div><br></div>