-
Notifications
You must be signed in to change notification settings - Fork 153
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
fix ODR violations #1604
Conversation
Thanks! |
@@ -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"}; |
There was a problem hiding this comment.
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 = [] { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
fixes some still left ODR violations