[llvm-bugs] [Bug 48705] New: clang-format removes space in front of && in macro
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Jan 10 10:59:04 PST 2021
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: unassignedclangbugs at nondot.org
Reporter: barry.revzin at gmail.com
CC: djasper at google.com, klimek at google.com,
llvm-bugs at lists.llvm.org
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210110/dd121373/attachment-0001.html>
More information about the llvm-bugs
mailing list