PiotrZSL added a comment.

In D141569#4139290 <https://reviews.llvm.org/D141569#4139290>, @ccotter wrote:

> In
>
>   template <int tagValue, typename T>
>   struct SomeClass
>   {
>   public:
>     explicit SomeClass(T&& value) : value(std::forward<T>(value)) {}
>    T value;
>   };
>
> `T` is not a universal reference in the constructor, it's an rvalue reference 
> to `T`. There is no deducing context, so universal references are not 
> involved here (and, `std::forward` would also be incorrect here). The 
> following would be a deducing context with a universal reference:

Wrong:

  #include <utility>
  
  template<typename T>
  struct Wrap {
  
    Wrap(T&& arg) 
      : value(arg)
    {}
  
    T value;  
  };
  
  struct Value {};
  
  int main()
  {
      Value value;
      Wrap<Value> v1(std::move(value));
      Wrap<Value> v2(std::move(value));
      Wrap<Value&> v3(value);
      return 0;
  }

If you add `std::move` you will get compilation error, if you add std::forward, 
everything will work fine. Simply Value& and && will evaluate to Value&, no 
rvalue reference here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141569/new/

https://reviews.llvm.org/D141569

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to