[clang] [clang-format] Fix a bug in annotating angles containing FatArrow (PR #108671)
kadir çetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 17 02:07:31 PDT 2024
================
@@ -243,14 +244,16 @@ class AnnotatingParser {
// operator that was misinterpreted because we are parsing template
// parameters.
// FIXME: This is getting out of hand, write a decent parser.
- if (InExpr && !Line.startsWith(tok::kw_template) &&
+ if (InExpr && !SeenFatArrow && !Line.startsWith(tok::kw_template) &&
Prev.is(TT_BinaryOperator)) {
const auto Precedence = Prev.getPrecedence();
if (Precedence > prec::Conditional && Precedence < prec::Relational)
return false;
}
if (Prev.isOneOf(tok::question, tok::colon) && !Style.isProto())
SeenTernaryOperator = true;
+ else if (Prev.is(TT_FatArrow))
----------------
kadircet wrote:
i don't think new or empty parantheses are a must either, the logic around here is just checking that `<>` are inside an expression, hence that kind of code pattern is likely quite common as people tend to do arithmetic via metaprogramming using these patterns. e.g:
```cpp
constexpr auto foo() { return FixedInt<N | M>(foo); }
```
this will be formatted as the following now:
```cpp
constexpr auto foo() { return FixedInt < N | M > (foo); }
```
https://github.com/llvm/llvm-project/pull/108671
More information about the cfe-commits
mailing list