[cfe-dev] Why is "..." printed 'After' the arg name in TypePrinter?
Richard Smith
richard at metafoo.co.uk
Tue Jul 22 20:25:50 PDT 2014
On Tue, Jul 22, 2014 at 1:40 AM, Manasij Mukherjee <manasij7479 at gmail.com>
wrote:
> Hi
> I was experimenting with printing out variadic templates with clang.
> I had a slight issue with how TypePrinter works for function arguments in
> variadic function templates.
>
> If I have this in my original source file:
> template <typename T, typename ...U>
> void foo(T t,U... args)
> {
>
> }
>
> TypePrinter currently generates this:
> U args...
> which should have been
> U... args
> as far as I know.
>
> Is there some policy I can set to change this behaviour?
>
> I had to slightly modify the the implementation to get what I expected.
>
> There are two functions in TypePrinter.cpp as follows:
>
> void TypePrinter::printPackExpansionBefore(const PackExpansionType *T,
> raw_ostream &OS) {
> printBefore(T->getPattern(), OS);
> OS << "...";
> }
> void TypePrinter::printPackExpansionAfter(const PackExpansionType *T,
> raw_ostream &OS) {
>
> printAfter(T->getPattern(), OS);
>
> }
>
> The line:
>
> OS << "...";
>
> was previously in printPackExpansionAfter.
>
> Why ?
> Any side effects of moving it to the before function, as I did ?
>
Yes. That'll break pretty-printing of template type argument packs:
template<typename ...T> void f() {
std::tuple<T[3] ...> t;
}
... would get pretty-printed as
std::tuple<T ...[3]> t;
... which is wrong.
Fixed in r213718.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140722/2fc8c6d7/attachment.html>
More information about the cfe-dev
mailing list