mardi 3 mai 2022

'Clang-Tidy: Do not implicitly decay an array into a pointer' when using std::forward and const char*

I do not understand why Clang-Tidy produces the error Clang-Tidy: Do not implicitly decay an array into a pointer in the following example:

struct Foo {
  explicit Foo(std::string _identifier) : identifier(std::move(_identifier)) {}

  std::string identifier;
};

struct Bar {
  template<typename... Ts>
  explicit Bar(Ts &&...args) : foo(std::forward<Ts>(args)...) {} // <-- Error

  Foo foo;
};

Bar bar("hello world");

From the error I understand that "hello world" being an array of type const char[11] (or similar) is decayed to type const char* somewhere during std::forward. But why and how can I fix this error? std::make_shared<Foo>("hello world") is very similar regarding usage of std::forward and does work.

Aucun commentaire:

Enregistrer un commentaire