Skip to content

Conversation

@Lastique
Copy link
Member

@Lastique Lastique commented Sep 6, 2025

At least on Linux, constants such as AF_INET, SOCK_STREAM and IPPROTO_TCP are implemented with unnamed enums, which makes these constants have different types in different translation units. This results in ODR violations as protocol_type struct ends up defined differently in every TU.

Also, static_protocol that is being instantiated with these constants also produces different types in each TU. While this by itself is not an ODR violation, it may generate lots of code and data duplication.

Avoid all of the above by using fixed types for family, type and protocol constants in protocol_type and static_protocol. Use int for each of the types, following POSIX socket(2) signature.

Fixes #242.

At least on Linux, constants such as AF_INET, SOCK_STREAM and
IPPROTO_TCP are implemented with unnamed enums, which makes these
constants have different types in different translation units.
This results in ODR violations as protocol_type struct ends up
defined differently in every TU.

Also, static_protocol that is being instantiated with these constants
also produces different types in each TU. While this by itself is not
an ODR violation, it may generate lots of code and data duplication.

Avoid all of the above by using fixed types for family, type and
protocol constants in protocol_type and static_protocol. Use int
for each of the types, following POSIX socket(2) signature.

Fixes boostorg#242.
@klemens-morgenstern
Copy link
Collaborator

In that case I might as well not bother defining the aliases and just use ints all the way?

The unamed enum seems to be used that way anyhow.

@Lastique
Copy link
Member Author

Lastique commented Sep 7, 2025

In that case I might as well not bother defining the aliases and just use ints all the way?

You could, but I kept the typedefs anyway as they are used in many places. It also offers an easy point of customization, if on some odd platform int is not appropriate for some reason.

@Lastique
Copy link
Member Author

Lastique commented Sep 7, 2025

The typedefs are also part of public interface, so removing them would be a breaking change.

@klemens-morgenstern klemens-morgenstern merged commit 7ff9397 into boostorg:develop Oct 6, 2025
22 of 24 checks passed
@Lastique Lastique deleted the feature/fix_odr_violation branch October 6, 2025 09:24
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.

ODR violation warnings

2 participants