vendredi 27 novembre 2020

clang-tidy readability-non-const-parameter warning, why?

I ran into an clang-tidy warning I don't understand. I've created a minimum example:

test.cpp:

#include <array>
#include <cstddef>

extern size_t get_data(float*const* buffers, size_t count);

size_t get_data_2_a(float* buffer1, float* buffer2)
{
  const std::array<float*, 2> buffers{buffer1, buffer2};
  return get_data(buffers.data(), buffers.size());
}

size_t get_data_2_b(float* buffer1, float* buffer2)
{
  float* buffers[] = {buffer1, buffer2};
  return get_data(buffers, sizeof(buffers) / sizeof(*buffers));
}

Running clang-tidy with:

clang-tidy -checks=readability-non-const-parameter test.cpp

clang-tidy output:

test.cpp:6:28: warning: pointer parameter 'buffer1' can be pointer to const [readability-non-const-parameter]
size_t get_data_2_a(float* buffer1, float* buffer2)
                           ^
                    const 
test.cpp:6:44: warning: pointer parameter 'buffer2' can be pointer to const [readability-non-const-parameter]
size_t get_data_2_a(float* buffer1, float* buffer2)
                                           ^
                                    const 

I've added those const's just to see what happens, clang-tidy still issues warnings:

test.cpp:6:34: warning: pointer parameter 'buffer1' can be pointer to const [readability-non-const-parameter]
size_t get_data_2_a(float* const buffer1, float* const buffer2)
                                 ^
                    const 
test.cpp:6:56: warning: pointer parameter 'buffer2' can be pointer to const [readability-non-const-parameter]
size_t get_data_2_a(float* const buffer1, float* const buffer2)
                                                       ^
                                          const 

clang-tidy version:

LLVM (http://llvm.org/):
  LLVM version 10.0.0
  
  Optimized build.
  Default target: x86_64-pc-linux-gnu
  Host CPU: znver2

I've tested it also using clang-tidy (trunk) at https://godbolt.org/z/P9xcEK

It only raises warning when using std::array, not when using a classic c-style array. What am I missing?

Aucun commentaire:

Enregistrer un commentaire