Skip to content

build(linux): fix compilation with Clang #3998

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AngryLoki
Copy link

@AngryLoki AngryLoki commented Jun 22, 2025

Description

Clang 20.1.7 fails with the following error:

/var/tmp/portage/net-misc/sunshine-2025.122.141614/work/Sunshine-2025.122.141614/src/platform/linux/misc.cpp:427:25: error: variable-sized object may not be initialized
  427 |       struct iovec iovs[(send_info.headers ? std::min(seg_max, send_info.block_count) : 1) * max_iovs_per_msg] = {};
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

As VLAs are not part of the C++ standard, Clang barely supports their features. However, simple memset fixes the issue.

Issues Fixed or Closed

  • N/A

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Dependency update (updates to dependencies)
  • Documentation update (changes to documentation)
  • Repository update (changes to repository files, e.g. .github/...)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated the in code docstring/documentation-blocks for new or existing methods/components

Clang 20.1.7 fails with the following error:
```
/var/tmp/portage/net-misc/sunshine-2025.122.141614/work/Sunshine-2025.122.141614/src/platform/linux/misc.cpp:427:25: error: variable-sized object may not be initialized
  427 |       struct iovec iovs[(send_info.headers ? std::min(seg_max, send_info.block_count) : 1) * max_iovs_per_msg] = {};
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

As VLAs are not part of the C++ standard, Clang barely support of their features. However, simple memset fixes the issue.
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
1 New issue
B Maintainability Rating on New Code (required ≥ A)
1 New Code Smells (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@AngryLoki AngryLoki changed the title Fix compilation with Clang build(linux): fix compilation with Clang Jun 22, 2025
@ReenigneArcher ReenigneArcher requested a review from Copilot June 22, 2025 22:45
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a Clang compilation error by replacing inline initialization of variable-length arrays with explicit memset zeroing.

  • Removed direct initializer usage for VLAs and added memset calls to clear memory.
  • Applied the same fix to both iovs and msgs arrays in different code blocks.
Comments suppressed due to low confidence (2)

src/platform/linux/misc.cpp:427

  • Consider adding a short inline comment explaining that memset is used here to zero initialize the variable-length array because direct initializer lists are not supported by Clang.
      struct iovec iovs[(send_info.headers ? std::min(seg_max, send_info.block_count) : 1) * max_iovs_per_msg];

src/platform/linux/misc.cpp:511

  • Similarly, add a brief comment alongside the memset calls for msgs and iovs to clarify that this approach is a workaround for Clang's limitations with variable-length array initialization.
      struct mmsghdr msgs[send_info.block_count];

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

Successfully merging this pull request may close these issues.

1 participant