<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58602>58602</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Wrong formatting of the pretty-printed return value of clang_getTypeSpelling()
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          vedgy
      </td>
    </tr>
</table>

<pre>
    When `clang_getTypeSpelling()` returns a value that contains `operator>` or `operator<=` followed by a closing angle bracket or `operator<` followed by an opening angle bracket, it does not insert whitespace between these two tokens. This makes the returned value invalid C++ and prevents *libclang* users from parsing it correctly. For example:

```cpp
namespace FormattingBug {
class X{};
bool operator>(X, int) { return true; }
bool operator<=(X, int) { return true; }
template<typename T> bool operator<(T, int) { return true; }

template<decltype(operator>)> class C{};
C<&operator> > gt;      // pretty-printed as "C<&operator>>"
C<&operator<= > le;     // pretty-printed as "C<&operator<=>"
C<&operator< <X>> lt;   // pretty-printed as "C<&operator<<FormattingBug::X>>"
}
```

When the space between the tokens is removed in the source code, like in the pretty-printed string, it does not compile. In simple cases like these, the user of `clang_getTypeSpelling()` can count the number of angle brackets and distinguish parts of operators from angle brackets. But this becomes unfeasible for more complicated types.

I believe `clang_getTypeSpelling()`, or more likely `QualType::print()` used by it, should insert a tab character between such tokens to pretty-print compilable code. The tab character is preferable to the space character here, because the users may rely on the fact that pretty-printed binary operators are surrounded by spaces to distinguish them from angle brackets.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVclu4zgQ_Rr5UhjDomPJOugQO91AHxsToHMbUFJJ4oQiBS7x-O-nSEkdL5medGDHNlnbe6-qVOnmXP7oUUGSbWrJVfdXh-75POKfI0opVJewfcIKugWDzhtlgcMblx7B9dxBrZXjgk7JQo9ouNMm2X4J9tpcHx6T7VM4b7WU-oQNVGeKVUttKQ1QaolQ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