title: Custom type conversion operator doesn't work when invoked on a forwarding reference (works when object is passed by value)
body: <p>I can't fathom the essence of this error so pardon me if the title could be better. This code fails to compile:</p>
  
  <pre><code>template &lt;auto v&gt;
  struct value_as_type {
      using type = decltype(v);    
      static constexpr type value {v};
      constexpr operator type() const {
          return v;
      }
  };
  
  template &lt;int First, int Last, typename Functor&gt;
  constexpr void static_for([[maybe_unused]] Functor&amp;&amp; f)
  {
      if constexpr (First &lt; Last)
      {
          f(value_as_type&lt;First&gt;{});
          static_for&lt;First + 1, Last, Functor&gt;(std::forward&lt;Functor&gt;(f));
      }
  }
  
  template &lt;class... FieldsSequence&gt;
  struct DbRecord
  {
  private:
      static constexpr bool checkAssertions()
      {
          static_assert(sizeof...(FieldsSequence) &gt; 0);
          static_for&lt;1, sizeof...(FieldsSequence)&gt;([](auto&amp;&amp; index) {
              constexpr int i = index;
              static_assert(i &gt; 0 &amp;&amp; i &lt; sizeof...(FieldsSequence));
          });
  
          return true;
      }
  
  private:
      static_assert(checkAssertions());
  };
  </code></pre>
  
  <p>The faulting line is <code>constexpr int i = index;</code>, and the error is "expression did not evaluate to a constant".</p>
  
  <p>Why is this? I expect the conversion operator of the <code>value_as_type&lt;int&gt;</code> object to be invoked. And most confusingly, it does work just fine if the lambda takes <code>auto index</code> rather than <code>auto&amp;&amp; index</code>.</p>
  
  <p>Online demo: <a href="https://godbolt.org/z/TffIIn" rel="nofollow noreferrer">https://godbolt.org/z/TffIIn</a></p>