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

    <tr>
        <th>Summary</th>
        <td>
            [ClangFormat] Space removed in `g< ::f<int>>()` except for `Standard: c++03`
        </td>
    </tr>

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

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

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

<pre>
    In all versions of C++ supported by ClangFormat, [the alternative operator spelling ("digraph") `<:` is treated as `[`](https://en.cppreference.com/w/cpp/language/operator_alternative). However, ClangFormat will remove a space between `<` and `:` (except when `Standard: c++03` is specified, or `Standard: Auto` is specified and no double-closing `>>` is found in the source file):

```c++
g< ::T>(); // before
g<::T>();        // after, compiler error
g [ : T > ( ) ;  // C++ equivalent tokenization
```

This causes problems when:

*   the first template parameter must use an absolute namespace (e.g., the code is in `f::g`, namespace `f::e` exists, and the parameter is `::e::T`), and
*   the code is not compiled with `-fno-digraphs` (or its equivalent in other compilers)

As far as I am aware, this is the only place where the "digraph" alternative spellings can change the meaning of otherwise-valid C++ code (and I believe there is no such case in C, where the digraph operators originated).

There is a (moderately annoying) workaround of adding a dummy comment:

```c++
g</**/ ::T>();  // safe
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyEVU2P4jgQ_TXmUgIFp8PAgQPQg3bO0_dVJS4n3nHsrO2QYX_9qpzQTc-OtK2oEeS56r1XH8YYTeuIjqI6i-p1hWPqfDgGupFL1t9WtVf34zcHaC3cKETjXQSv4SLkWcgzxHEYfEikoL7DxaJrrz70mIS8gKjOqSNAmyg4TOZG4AcKmHyAOJC1xrUg5F5IqUwbcOiElEIeQOwKUV5EeRK7AkyEFAg5Bcb8qjrn_69C7ruUhshAeRXySm7TDEMgTYFcQ5vG90JeJyGvzTAIeWV6I7Yk5PVB5M8ndkIeNvCHn-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