google / google/benchmark

[BUG] Build fails in benchmark.cc with Clang 13 on Windows

Open
#1,277 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C++
Stars
10.4k
Forks
1.8k
Avg merge
2d 4h
Merged PRs (30d)
8

Description

**Describe the bug**
Clang 13 on Windows emits an error on compilation of `benchmark.cc`:

```
..\..\3rdparty\benchmark\src\benchmark.cc(173,17): error: static_assert expression is not an integral constant expression
static_assert(offsetof(State, error_occurred_) <=
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt\stddef.h(47,31): note: expanded from macro 'offsetof'
#define offsetof(s,m) ((::size_t)&reinterpret_cast((((s*)0)->m)))
^
..\..\3rdparty\benchmark\src\benchmark.cc(173,17): note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression
C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt\stddef.h(47,32): note: expanded from macro 'offsetof'
#define offsetof(s,m) ((::size_t)&reinterpret_cast((((s*)0)->m)))
^
1 error generated.
```

**System**
Which OS, compiler, and compiler version are you using:
- OS: Windows 10
- Compiler and version: Clang 13.0.0, Visual Studio 2019 16.11.5

**Additional Information**:
Defining `_CRT_USE_BUILTIN_OFFSETOF` as mentioned in `stddef.h` lets the file compile successfully.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.