Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'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.

like image 412
jawa Avatar asked Nov 14 '25 17:11

jawa


1 Answers

This looks like a bogus diagnostic. I would disable it globally, since this usecase is so common.

like image 126
HolyBlackCat Avatar answered Nov 17 '25 09:11

HolyBlackCat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!