[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

Piotr Zegar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 20 10:34:48 PST 2023


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



More information about the cfe-commits mailing list