vs-sourcetrail
vs-sourcetrail copied to clipboard
"offsetof" errors when indexing
- Put something like this in a VS C++ project
struct Foo { float x; };
void main() { static_assert(offsetof(Foo, x) == 0); }
- Create compilation db and index it.
- Note the compile error on the static_assert.
This causes a compile error when indexing. MS's stddef.h contains this code to detect versions of their compiler that don't have a built-in offsetof. In that case, it subsitutes a fallback that doesn't work with static_assert because it's not a compile-time constant:
#if defined _MSC_VER && !defined _CRT_USE_BUILTIN_OFFSETOF
#ifdef __cplusplus
#define offsetof(s,m) ((::size_t)&reinterpret_cast<char const volatile&>((((s*)0)->m)))
clang's pretending to be _MSC, and (I think) vs-sourcetrail is putting MS's headers before clang's. One solution might be for vs-sourcetrail to put -D_CRT_USE_BUILTIN_OFFSETOF on the clang command line.
See https://bugreports.qt.io/browse/QTCREATORBUG-19266 for a similar issue (using clang tooling to analyze MSVC code)