Skip to content

Stop requiring an out of class definition for version traits - #370

Open
gennaroprota wants to merge 1 commit into
developfrom
fix/version-trait-needs-no-out-of-class-definition
Open

Stop requiring an out of class definition for version traits#370
gennaroprota wants to merge 1 commit into
developfrom
fix/version-trait-needs-no-out-of-class-definition

Conversation

@gennaroprota

Copy link
Copy Markdown
Collaborator

version_type took its argument by reference, so constructing one from version<T>::value could bound a reference to that static data member and ODR-used it. A trait written by hand with no out-of-class definition for the data member, then left an undefined reference behind on compilers which do not fold the constant away. Spelling the value as an int happened to work only because the conversion to unsigned int created a temporary for the reference to bind to.

Taking the argument by value removes the ODR-use, so both int and unsigned int work. The specializations BOOST_CLASS_VERSION writes have no definition either, and were relying on the same accident. object_id_type had the same constructor and is changed along with it.

Fixes #311.

`version_type` took its argument by reference, so constructing one from
`version<T>::value` could bound a reference to that static data member
and ODR-used it.  A trait written by hand with no out-of-class
definition for the data member, then left an undefined reference behind
on compilers which do not fold the constant away.  Spelling the value as
an `int` happened to work only because the conversion to `unsigned int`
created a temporary for the reference to bind to.

Taking the argument by value removes the ODR-use, so both `int` and
`unsigned int` work. The specializations `BOOST_CLASS_VERSION` writes
have no definition either, and were relying on the same accident.
`object_id_type` had the same constructor and is changed along with it.

Fixes #311.
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.

[Question] Is the version<...>::value an int or unsigned int? i have link problems with gcc but not with MSVC

1 participant