Skip to content
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

fix ODR violations #1604

Merged
merged 1 commit into from
Feb 7, 2025
Merged

Conversation

arturbac
Copy link
Contributor

@arturbac arturbac commented Feb 7, 2025

fixes some still left ODR violations

@stephenberry
Copy link
Owner

Thanks!

@stephenberry stephenberry merged commit 820a66d into stephenberry:main Feb 7, 2025
12 checks passed
@@ -49,7 +49,7 @@ namespace glz::rpc
namespace glz::rpc
{
using id_t = std::variant<glz::json_t::null_t, std::string_view, std::int64_t>;
static constexpr std::string_view supported_version{"2.0"};
inline constexpr std::string_view supported_version{"2.0"};
Copy link
Collaborator

Choose a reason for hiding this comment

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

static constexpr implies inline, so it's better here to stick with static constexpr.

@@ -25,7 +25,7 @@ namespace glz::detail
Comment = '/'
};

constexpr std::array<json_type, 256> json_types = [] {
inline constexpr std::array<json_type, 256> json_types = [] {
Copy link
Collaborator

@sjanel sjanel Feb 8, 2025

Choose a reason for hiding this comment

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

What about making sure that all the constexpr variables are static constexpr instead?

Copy link
Owner

Choose a reason for hiding this comment

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

static constexpr implies one definition per compile unit. inline constexpr means one definition across all compile units, merged my the linker.

Copy link
Contributor Author

@arturbac arturbac Feb 8, 2025

Choose a reason for hiding this comment

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

constexpr by default implies static - internal to translation unit linking, so address after including and defining is different for every translation unit.
inline constexpr - forces linker to make sure all translation units will use only one instance with the same address of given variable/constant.
The result of using (static) constexpr variable is almost harmless only blows You executable as long U don't compare pointers. But when You will pass address of such variable across multiple translation units and compare to itself address will be not equal to.
so in simple words

A.cpp and B.cpp #include <header> with constexpr std::array<json_type, 256> json_types.
&json_types[0] from A.cpp != &json_types[0] B.cpp

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.

3 participants