Skip to content

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

Merged
sloriot merged 1 commit into
CGAL:masterfrom
bangerth:inline
May 16, 2025
Merged

sloriot merged 1 commit into
CGAL:masterfrom
bangerth:inline

Conversation

@bangerth

@bangerth bangerth commented May 5, 2025

Copy link
Copy Markdown
Contributor

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

sloriot commented May 16, 2025

Copy link
Copy Markdown
Member

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
@bangerth
bangerth deleted the inline branch May 17, 2025 18:23
efifogel pushed a commit to efifogel/cgal that referenced this pull request Jan 14, 2026
…#8874)

## 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 CGAL#8871. Related to
dealii/dealii#18071.

## Release Management

* Affected package(s): 5.6.1
* Issue(s) solved (if any): CGAL#8871
* License and copyright ownership: Same license as used throughout CGAL.
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