https://bugs.llvm.org/show_bug.cgi?id=48705
Bug ID: 48705
Summary: clang-format removes space in front of && in macro
Product: clang
Version: 11.0
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: Formatter
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected],
[email protected]
Consider the following example:
#include <type_traits>
template <typename T> inline constexpr bool check = true;
#define REQUIRES(...) std::enable_if_t<(__VA_ARGS__), int> = 0
template <typename T, REQUIRES(check<T> && check<T*>)>
void foo(T) { }
template <typename T, std::enable_if_t<(check<T> && check<T*>), int> = 0>
void bar(T) { }
The REQUIRES macro here allows for a nice way of writing constraints before
C++20. The foo and bar function templates here are just different ways of
writing the same thing, the macro just reads [quite a bit] nicer.
With a .clang-format file consisting entirely of:
BasedOnStyle: Google
The above header gets formatted as:
#include <type_traits>
template <typename T>
inline constexpr bool check = true;
#define REQUIRES(...) std::enable_if_t<(__VA_ARGS__), int> = 0
template <typename T, REQUIRES(check<T>&& check<T*>)>
void foo(T) {}
template <typename T, std::enable_if_t<(check<T> && check<T*>), int> = 0>
void bar(T) {}
For foo, the && in the REQUIRES is moved over to the left... as if we're
declaring an rvalue reference of type check<T>. But in bar, the && stays spaced
out.
This should be formatted as:
template <typename T, REQUIRES(check<T> && check<T*>)>
void foo(T) {}
--
You are receiving this mail because:
You are on the CC list for the bug._______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs