Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@astrelni

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.

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