Fixes https://github.com/llvm/llvm-project/issues/53876.
This is a solution for standard C++ casts: const_cast, dynamic_cast, reinterpret_cast, static_cast.
A general approach handling all possible casts is not possible without semantic information.
Consider the code:
static_cast<T>(*function_pointer_variable)(arguments);
vs.
some_return_type<T> (*function_pointer_variable)(parameters); // Later used as: function_pointer_variable = &some_function; return function_pointer_variable(args);
In the latter case, it's not a cast but a variable declaration of a pointer to function.
Without knowing what some_return_type<T> is (and clang-format does not know it), it's hard to distinguish between the two cases. Theoretically, one could check whether "parameters" are types (not a cast) and "arguments" are value/expressions (a cast), but that might be inefficient (needs lots of lookahead).
To add some context, in the failing cases, the opening parenthesis was set to type TT_FunctionTypeLParen that we don't want because combined with a * after the next paren, it adds a space (cf. https://github.com/llvm/llvm-project/blob/331e8e4e27be5dd673898a89a7cf00e76903216a/clang/lib/Format/TokenAnnotator.cpp#L3105-L3109).