<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">I would directly use John McCall’s suggested code in the review (`getPointerDepth(QualType type)` etc) to simply compare pointer depths of the arg and param types, instead of comparing the results of `getInnermostPointerType(…)` — not sure what that function is doing, particularly given it uses getPointeeOrArrayElementType to look through pointers, which seems to defeat the purpose of the comparison (to print arrays different from pointers).  </div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Apr 20, 2021, at 2:33 PM, Pratyush Das via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">Hi,</div><div class=""><br class=""></div><div class="">My question is motivated by <a href="https://reviews.llvm.org/D36368" class="">https://reviews.llvm.org/D36368</a> (current WIP diff - <a href="https://github.com/llvm/llvm-project/compare/main...reikdas:array-axel" class="">https://github.com/llvm/llvm-project/compare/main...reikdas:array-axel</a>).</div><div class=""><br class=""></div><div class="">For the following code snippet - <br class=""></div><div class=""><br class=""></div><div class=""><span style="font-family:monospace" class="">constexpr const char **kZero[] = {};</span></div><div class=""><span style="font-family:monospace" class=""><br class=""></span></div><div class=""><span style="font-family:monospace" class="">// Let's call this (1)<br class=""></span></div><div class=""><span style="font-family:monospace" class="">template <const char *const *const *, typename T> class Jolumn {};<br class=""></span></div><div class=""><span style="font-family:monospace" class="">Jolumn<kZero, double>();</span></div><div class=""><span style="font-family:monospace" class=""><br class=""></span></div><div class=""><span style="font-family:monospace" class="">// Let's call this (2)<br class=""></span></div><div class=""><span style="font-family:monospace" class="">template <const char** const (*)[0], typename T> class Iolumn {};</span></div><div class=""><span style="font-family:monospace" class="">Iolumn<&kZero, double>();</span><br class=""></div><div class=""><br class=""></div><div class="">I want to be able to detect if an ampersand should be printed for (1) and (2) (it shouldn't be for (1) and should be for (2)).<br class=""></div><div class=""><br class=""></div><div class="">Looking at the type dumps,</div><div class="">the parameter type(the first parameter type for both class Jolumn and class Iolumn) is represented as - <br class=""></div><div class=""><span style="font-family:monospace" class="">ConstantArrayType 0x560d4eab8000 'const char **const [0]' 0 <br class="">`-QualType 0x560d4eab7de1 'const char **const' const<br class="">  `-PointerType 0x560d4eab7de0 'const char **'<br class="">    `-PointerType 0x560d4ea72930 'const char *'<br class="">      `-QualType 0x560d4ea71e61 'const char' const<br class="">        `-BuiltinType 0x560d4ea71e60 'char'</span></div></div></div></blockquote><div><br class=""></div><div>In my local clang the above is the type of only the Iolumn parameter; the Jolumn parameter is </div><div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class="">PointerType 0x7ff4ed061b30 'const char *const *const *'</div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class="">`-…etc</div></div><div><br class=""></div><div>If those types are indeed the same in yours, that is a problem, so double check those types if it still doesn’t work.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">the argument type for kZero in (1) is represented as -</div><div class=""><span style="font-family:monospace" class="">PointerType 0x5560fe683130 'const char *const *const *'<br class="">`-QualType 0x5560fe683101 'const char *const *const' const<br class="">  `-PointerType 0x5560fe683100 'const char *const *'<br class="">    `-QualType 0x5560fe63d951 'const char *const' const<br class="">      `-PointerType 0x5560fe63d950 'const char *'<br class="">        `-QualType 0x5560fe63ce81 'const char' const<br class="">          `-BuiltinType 0x5560fe63ce80 'char'</span></div><div class=""><br class=""></div><div class="">the argument type for &kZero in (2) is represented as -</div><div class=""><span style="font-family:monospace" class="">PointerType 0x560d4eab8100 'const char **const (*)[0]'<br class="">`-QualType 0x560d4eab7fc1 'const char **const[0]' const<br class="">  `-ConstantArrayType 0x560d4eab7fc0 'const char **[0]' 0 <br class="">    `-PointerType 0x560d4eab7de0 'const char **'<br class="">      `-PointerType 0x560d4ea72930 'const char *'<br class="">        `-QualType 0x560d4ea71e61 'const char' const<br class="">          `-BuiltinType 0x560d4ea71e60 'char'</span></div><div class=""><br class=""></div><div class="">From the clang::Type, how do I detect that an ampersand should not be printed for the argument kZero (1), but should be printed for the argument &kZero (2)?<br class=""></div><div class=""><br class=""></div><div class="">Comparing the pointer depths of the two as suggested in the review or comparing the innermost clang::PointerType give the same result for both the argument types.<br class=""></div><div class="">I also cycled through the relevant boolean methods in <a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html" class="">https://clang.llvm.org/doxygen/classclang_1_1Type.html</a>, but the methods gave the same results for both the argument types.</div><div class=""><br class=""></div><div class="">I would really appreciate any help. <br class=""></div><div class=""><br class=""></div><div class="">Thanks!<br class=""></div><div class=""><br class=""></div><br class="">-- <br class=""><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class="">Pratyush Das<br class=""></div></div></div></div></div></div>
_______________________________________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a><br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev<br class=""></div></blockquote></div><br class=""></body></html>