title: Compare std::variant with int using C++20 <=> is not a constant expression
body: <p>Since the <code>std::variant</code> is not allowed to compare with one of its alternative types in the standard library, I am implementing the compare function using C++20 <code>&lt;=&gt;</code> operator:</p>
  <pre><code>template &lt;typename... Args, typename T&gt;
  constexpr auto operator&lt;=&gt;(const std::variant&lt;Args...&gt;&amp; v, const T&amp; t) {
    return std::visit([&amp;t](const auto&amp; u) -&gt; std::partial_ordering {
      if constexpr (requires { u &lt;=&gt; t; }) return u &lt;=&gt; t;
      else return std::partial_ordering::unordered;
    }, v);
  }
  </code></pre>
  <p>But when I testing the above function with my own defined <code>std::variant</code>:</p>
  <pre><code>using Variant = std::variant&lt;double, int, std::string_view&gt;;
  constexpr Variant v1{1.0};
  constexpr Variant v2{1};
  constexpr Variant v3{&quot;hello&quot;};
  static_assert(v1 &lt; 2);
  // compile error
  static_assert(v2 &lt; 2);
  static_assert(!(v3 &gt; 2) &amp;&amp; !(v3 &lt; 2) &amp;&amp; !std::is_eq(v3 &lt;=&gt; 2));
  </code></pre>
  <p><a href="https://godbolt.org/z/o3vbE1" rel="nofollow noreferrer"><strong>The second assertion couldn't compile</strong></a>, GCC says:</p>
  <pre><code>&lt;source&gt;:19:17: error: non-constant condition for static assertion
     19 |   static_assert(v2 &lt; 2);
        |                 ^~~~~~~~~
  &lt;source&gt;:19:24:   in 'constexpr' expansion of 'operator&lt;=&gt;&lt;double, int, std::basic_string_view&lt;char, std::char_traits&lt;char&gt; &gt;, int&gt;(v2, 2)'
  &lt;source&gt;:19:17: error: '&lt;anonymous&gt;' is not a constant expression
  </code></pre>
  <p>Why is <code>v2 &lt; 2</code> not a constant expression? or it's just a <strong>GCC bug</strong>? Weirder, when I change the second assertion to compare with <code>double</code>, this can compile:</p>
  <pre><code>static_assert(v2 &lt; 2.0);
  </code></pre>
  <p><strong>Update:</strong></p>
  <p><a href="https://godbolt.org/z/fnEfdE" rel="nofollow noreferrer"><strong>Clang can pass three assertions, but MSVC can only pass the third assertion</strong></a>, <strong>it seems MSVC also has a bug.</strong></p>