Skip to content

Use of offsetof macro on non standard-layout type is undefined at least prior to C++17 #552

Description

@astrelni

To the best of my understanding benchmark.cc#L316, which calls offsetof on benchmark::State, is undefined behavior.

C++11 18.2.4 [support.types]

The macro offsetof(type, member-designator) accepts a restricted set of type arguments in this International Standard. If type is not a standard-layout class (Clause 9), the results are undefined.

benchmark::State is a non standard-layout type because all of its non-static members do not have the same access control.

I am not sure what would be lost by just removing the static_assert, so I am starting this off as an issue instead of going straight for a PR.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions