“Clang-Tidy:使用 std::forward 和 const char* 时,不要将数组隐式衰减为指针”

jaw*_*awa 5 c++ c++11 clang-tidy

Clang-Tidy: Do not implicitly decay an array into a pointer 我不明白为什么 Clang-Tidy在以下示例中产生错误:

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");

Run Code Online (Sandbox Code Playgroud)

从错误中我了解到,"hello world"作为类型(或类似)的数组const char[11]会在 期间衰减到const char*某个位置std::forward。但为什么以及如何修复这个错误呢?std::make_shared<Foo>("hello world")与 的用法非常相似std::forward并且确实有效。

Hol*_*Cat 3

这看起来像是一个虚假的诊断。我会全局禁用它,因为这个用例非常常见。