Quantcast
Channel: User HolyBlackCat - Stack Overflow
Viewing all articles
Browse latest Browse all 1313

Overloaded `&&`/`||` operators in concepts and requires-clauses

$
0
0

I made a macro for the "implies" operator. It works fine in general, but breaks on Clang when used in a concept or a requires-clause.

run on gcc.godbolt.org

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 says:

<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{}||      |                   ^~~~~~~~~~~~~~~~~~~

While GCC and MSVC happily accept this code. Which compiler is correct?


Viewing all articles
Browse latest Browse all 1313

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>