Issue 123823
Summary [ClangFormat] Space removed in `g< ::f<int>>()` except for `Standard: c++03`
Labels new issue
Assignees
Reporter reventlov
    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
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to