[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 3 12:02:16 PST 2024


zygoloid wrote:

> > Another possibility to consider for the original bug: `(single_identifier)` is almost certainly a cast, not redundant parentheses, unless `single_identifier` names a macro argument. So I wonder if that would be a better heuristic to use to fix the regression.
> 
> I don’t think that would work as`(identifier)` can be a number of constructs depending on the context. It can be part of a function/macro call, function declaration, macro definition, C++ cast, C cast, `sizeof` operand, etc.

OK, but the context is deciding whether `(identifier)&x` or `(identifier)*x` is a binary operator or a cast. Given no other information, the fact that it's a single identifier seems like a very strong signal that it's a cast.

I don't think this PR fixes #83400 -- handling a small handful of common types won't address the same issue for the much larger class of cases where the type name is not one of these types. Eg, in #83400 itself the examples included:

```diff
-		static _FORCE_INLINE_ m_type get(const Variant *v) { return (m_type)*VariantInternal::get_int(v); }    \
+		static _FORCE_INLINE_ m_type get(const Variant *v) { return (m_type) * VariantInternal::get_int(v); }  \
```

But looking for a parenthesized single identifier addresses all of the examples in the issue.

https://github.com/llvm/llvm-project/pull/83709


More information about the cfe-commits mailing list