Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid modernize-avoid-c-arrays warning with templates that deduce array length #60053

Open
firewave opened this issue Jan 15, 2023 · 1 comment

Comments

@firewave
Copy link

firewave commented Jan 15, 2023

#include <cstdint>

template<typename T, int size>
std::size_t arrayLen(const T (& /*unused*/)[size])
{
    return size;
}
<source>:4:28: warning: do not declare C-style arrays, use std::array<> instead [modernize-avoid-c-arrays]
std::size_t arrayLen(const T (& /*unused*/)[size])
                           ^

https://godbolt.org/z/bvWbTqP1f

In our case this is used to get the length of a string literal. It doesn't make sense to use std::array for that.

So before C++17 you can only suppress this as std::string_view, which would allow to get rid of this, is not yet available.

@llvmbot
Copy link
Member

llvmbot commented Jan 16, 2023

@llvm/issue-subscribers-clang-tidy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants