[cfe-dev] Determining whether to print references for array type
Pratyush Das via cfe-dev
cfe-dev at lists.llvm.org
Tue Apr 20 11:33:31 PDT 2021
Hi,
My question is motivated by https://reviews.llvm.org/D36368 (current WIP
diff -
https://github.com/llvm/llvm-project/compare/main...reikdas:array-axel).
For the following code snippet -
constexpr const char **kZero[] = {};
// Let's call this (1)
template <const char *const *const *, typename T> class Jolumn {};
Jolumn<kZero, double>();
// Let's call this (2)
template <const char** const (*)[0], typename T> class Iolumn {};
Iolumn<&kZero, double>();
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)).
Looking at the type dumps,
the parameter type(the first parameter type for both class Jolumn and class
Iolumn) is represented as -
ConstantArrayType 0x560d4eab8000 'const char **const [0]' 0
`-QualType 0x560d4eab7de1 'const char **const' const
`-PointerType 0x560d4eab7de0 'const char **'
`-PointerType 0x560d4ea72930 'const char *'
`-QualType 0x560d4ea71e61 'const char' const
`-BuiltinType 0x560d4ea71e60 'char'
the argument type for kZero in (1) is represented as -
PointerType 0x5560fe683130 'const char *const *const *'
`-QualType 0x5560fe683101 'const char *const *const' const
`-PointerType 0x5560fe683100 'const char *const *'
`-QualType 0x5560fe63d951 'const char *const' const
`-PointerType 0x5560fe63d950 'const char *'
`-QualType 0x5560fe63ce81 'const char' const
`-BuiltinType 0x5560fe63ce80 'char'
the argument type for &kZero in (2) is represented as -
PointerType 0x560d4eab8100 'const char **const (*)[0]'
`-QualType 0x560d4eab7fc1 'const char **const[0]' const
`-ConstantArrayType 0x560d4eab7fc0 'const char **[0]' 0
`-PointerType 0x560d4eab7de0 'const char **'
`-PointerType 0x560d4ea72930 'const char *'
`-QualType 0x560d4ea71e61 'const char' const
`-BuiltinType 0x560d4ea71e60 'char'
>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)?
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.
I also cycled through the relevant boolean methods in
https://clang.llvm.org/doxygen/classclang_1_1Type.html, but the methods
gave the same results for both the argument types.
I would really appreciate any help.
Thanks!
--
Pratyush Das
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20210421/746fdf4c/attachment.html>
More information about the cfe-dev
mailing list