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

标签 c++ c++11 clang-tidy

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

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

从错误中我了解到 "hello world"const char[11] 类型的数组(或类似的)被衰减为类型 const char*std::forward 期间的某处.但是为什么以及如何修复此错误? std::make_shared<Foo>("hello world")关于 std::forward 的用法非常相似并且确实有效。

最佳答案

这看起来像一个虚假的诊断。我会在全局范围内禁用它,因为这个用例很常见。

关于c++ - 'Clang-Tidy:在使用 std::forward 和 const char* 时,不要将数组隐式衰减为指针',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72101801/

相关文章:

C++:引用静态库的静态库

c++ - Include 语句包含自身

c++ - 背包算法,如何获得更好的性能?

c++ - 比较两个包含字符串的 vector 的快速方法

c++ - 让 clang-tidy 修复头文件

c++ - 在 Cmake 中为 clang-tidy 提供 header 过滤器的正确方法是什么?

c++ - 为什么我使用 substr 调用会超出范围?

c++ - 如何通过在运行时编辑文件来设置窗口属性?

c++ - 就地 std::copy_if

windows - clang-tidy 在 Windows 上使用 MSVC2015