<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - clang-format removes space in front of && in macro"
href="https://bugs.llvm.org/show_bug.cgi?id=48705">48705</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>clang-format removes space in front of && in macro
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>11.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Formatter
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>barry.revzin@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>djasper@google.com, klimek@google.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>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) {}</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>