Skip to content

Mark variables declared at global scope in headers as 'inline'. #8874

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

Merged
merged 1 commit into from
May 16, 2025

Conversation

bangerth
Copy link
Contributor

@bangerth bangerth commented May 5, 2025

Summary of Changes

const variables declared at global scope have internal linkage, and so if they are declared in a header file, they are replicated in every file that #include the header. They also can't be the target of using declarations that exports the variable into a C++20 module. This change marks a number of variables with inline, which gives these variables external linkage, allows the linker to unify all of these variables between different .o files, and also allows for their use in C++20 modules.

There is a separate question whether these variables could or should be constexpr instead of just const. The difference between constexpr and const has no effect on linkage, and so in the spirit of taking one step at a time, this patch does not address the constexpr vs const question.

This patch fixes #8871. Related to dealii/dealii#18071.

Release Management

@MaelRL MaelRL added this to the 6.1-beta milestone May 5, 2025
@MaelRL MaelRL added Bug named parameters Not yet approved The feature or pull-request has not yet been approved. labels May 5, 2025
@MaelRL MaelRL requested a review from sloriot May 5, 2025 14:42
@lrineau lrineau added Ready to be tested and removed Not yet approved The feature or pull-request has not yet been approved. labels May 6, 2025
@sloriot
Copy link
Member

sloriot commented May 16, 2025

Successfully tested in CGAL-6.1-Ic-155

note that constexpr are added by #7966

@sloriot sloriot merged commit 8978dde into CGAL:master May 16, 2025
8 checks passed
@bangerth bangerth deleted the inline branch May 17, 2025 18:23
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.

Let global variables have external linkage.
4 participants