我为“implies”运算符创建了一个宏。它通常运行良好,但在概念或要求子句中使用时,Clang 会中断。
namespace detail
{
template <typename T>
concept BoolLike = requires(T &&t) {(T &&)t ? true : false;};
struct Implies
{
template <BoolLike T>
friend constexpr bool operator||(T &&lhs, Implies)
{
return !bool((T &&)lhs);
}
};
}
#define IMPLIES ||::detail::Implies{}||
template <typename T>
concept A = true IMPLIES true;
static_assert(A<int>);
Clang 说:
<source>:19:18: error: atomic constraint must be of type 'bool' (found '::detail::Implies')
19 | concept A = true IMPLIES true;
| ^~~~~~~
<source>:16:19: note: expanded from macro 'IMPLIES'
16 | #define IMPLIES ||::detail::Implies{}||
| ^~~~~~~~~~~~~~~~~~~
虽然 GCC 和 MSVC 很乐意接受此代码。哪个编译器是正确的?