Skip to content

Preclude C-style arrays - #3251

Merged
Lestropie merged 6 commits into
devfrom
check_syntax_no_c_arrays
Jan 13, 2026
Merged

Lestropie merged 6 commits into
devfrom
check_syntax_no_c_arrays

Conversation

@Lestropie

Copy link
Copy Markdown
Member

Further extension of #3212.

Closes #3240.

There was a comment in #2665 that it would be preferable to avoid the use of C-style arrays, and it immediately occurred to me that we should be able to enforce this; as noted in #3243 this may not be an optimal solution, but it's possible, and I was having fun with regexes.

Note that there's a somewhat unrelated change hidden in here: sh2peaks was using its own direction set, and in trying to refactor for this change it was vastly easier to instead make use of the internally-defined set. But this does mean that there's scope for the outcomes of that command to change; and also it may not be terribly discoverable being part of this PR. So it might be safer for me to create that in a standalone PR.

github-actions[bot]

This comment was marked as outdated.

Conflicts:
	cpp/core/dwi/tractography/GT/particlegrid.cpp
	cpp/core/dwi/tractography/GT/particlegrid.h
github-actions[bot]

This comment was marked as outdated.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 25 out of 28. Check the log or trigger a new build to see more.

Comment thread cpp/cmd/tckconvert.cpp
points.resize(3 * number_of_points);
input.read((char *)points.data(), 3 * number_of_points * sizeof(float));
input.read(reinterpret_cast<char *>(points.data()),
3UL * static_cast<unsigned long>(number_of_points) * sizeof(float));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: narrowing conversion from 'unsigned long' to signed type 'streamsize' (aka 'long') is implementation-defined [bugprone-narrowing-conversions]

                   3UL * static_cast<unsigned long>(number_of_points) * sizeof(float));
                   ^

for (size_t neighbour_index = 0; neighbour_index != 8; ++neighbour_index) {
assign_pos_of(lower_corner + neighbour_offsets[neighbour_index]).to(voxel);
in_vertex_values[neighbour_index] = 0.0f;
in_vertex_values[neighbour_index] = 0.0F;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use array subscript when the index is not an integer constant expression [cppcoreguidelines-pro-bounds-constant-array-index]

          in_vertex_values[neighbour_index] = 0.0F;
          ^

const uint32_t indices[3]{edge_to_output_vertex[*first_edge],
edge_to_output_vertex[*(first_edge + 2)],
edge_to_output_vertex[*(first_edge + 1)]};
const auto &row = cube_triangle_table[code];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use array subscript when the index is not an integer constant expression [cppcoreguidelines-pro-bounds-constant-array-index]

        const auto &row = cube_triangle_table[code];
                          ^

edge_to_output_vertex[*(first_edge + 1)]};
const auto &row = cube_triangle_table[code];
for (ssize_t first_edge_index = 0; row[first_edge_index] >= 0; first_edge_index += 3) {
const std::array<uint32_t, 3> indices{edge_to_output_vertex[row[first_edge_index]],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use array subscript when the index is not an integer constant expression [cppcoreguidelines-pro-bounds-constant-array-index]

          const std::array<uint32_t, 3> indices{edge_to_output_vertex[row[first_edge_index]],
                                                ^

const auto &row = cube_triangle_table[code];
for (ssize_t first_edge_index = 0; row[first_edge_index] >= 0; first_edge_index += 3) {
const std::array<uint32_t, 3> indices{edge_to_output_vertex[row[first_edge_index]],
edge_to_output_vertex[row[first_edge_index + 2]],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use array subscript when the index is not an integer constant expression [cppcoreguidelines-pro-bounds-constant-array-index]

                                                edge_to_output_vertex[row[first_edge_index + 2]],
                                                ^

Comment thread cpp/gui/opengl/font.h
int font_width[256], font_height;
float font_tex_pos[256], font_tex_width[256];
std::array<int, 256> font_width;
int font_height;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable 'font_height' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  int font_height;
      ^

Comment thread cpp/gui/opengl/font.h
float font_tex_pos[256], font_tex_width[256];
std::array<int, 256> font_width;
int font_height;
std::array<float, 256> font_tex_pos;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable 'font_tex_pos' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  std::array<float, 256> font_tex_pos;
                         ^

Comment thread cpp/gui/opengl/font.h
std::array<int, 256> font_width;
int font_height;
std::array<float, 256> font_tex_pos;
std::array<float, 256> font_tex_width;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable 'font_tex_width' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  std::array<float, 256> font_tex_width;
                         ^


protected:
GLfloat v[4];
std::array<GLfloat, 4> v;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable 'v' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  std::array<GLfloat, 4> v;
                         ^


protected:
GLfloat m[16];
std::array<GLfloat, 16> m;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable 'm' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  std::array<GLfloat, 16> m;
                          ^

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread cpp/gui/projection.h
protected:
GL::mat4 MV, iMV, P, iP, MVP, iMVP;
GLint viewport[4];
std::array<GLint, 4> viewport;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable 'viewport' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  std::array<GLint, 4> viewport;
                       ^


protected:
GLuint index[3];
std::array<GLuint, 3> index;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable 'index' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  std::array<GLuint, 3> index;
                        ^

Comment thread cpp/gui/shapes/sphere.cpp

protected:
GLuint index[3];
std::array<GLuint, 3> index;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable 'index' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  std::array<GLuint, 3> index;
                        ^

@Lestropie
Lestropie merged commit 9ee573d into dev Jan 13, 2026
6 checks passed
@Lestropie
Lestropie deleted the check_syntax_no_c_arrays branch January 13, 2026 03:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants