Clang-format using templates and greater than comparison
I noticed some weird result when running clang-format on our code base. The issue seems to be linked to the use of templates and a greater than comparison. The following snippet is the code that needs to be formatted:
#include <iostream>
#include <tuple>
template <typename T>
auto test(T t) noexcept -> void {
if constexpr (std::tuple_size_v<T> > 0)
std::cout << "Not empty" << std::endl;
else
std::cout << "Empty" << std::endl;
}
int main(void) {
test(std::tuple{});
test(std::tuple{1, "g"});
}
clang-format 13 (and also more recent versions it seems), changes the following line like this:
-if constexpr (std::tuple_size_v<T> > 0)
+if constexpr (std::tuple_size_v < T >> 0)
The formatting has been set to Google, all other configuration options are just using default values.
Note: since tuple_size_v returns an unsigned integer, we changed our code to if constexpr (std::tuple_size_v<T> != 0) to work around this issue.
It seems like the angles is parsed as not matched due to this line: TokenAnnotator.cpp:169.
@llvm/issue-subscribers-clang-format
https://reviews.llvm.org/D140843