vs-sourcetrail icon indicating copy to clipboard operation
vs-sourcetrail copied to clipboard

"offsetof" errors when indexing

Open dubois opened this issue 4 years ago • 1 comments

  1. Put something like this in a VS C++ project
  struct Foo { float x; };
  void main() { static_assert(offsetof(Foo, x) == 0); }
  1. Create compilation db and index it.
  2. 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.

dubois avatar Apr 29 '20 00:04 dubois

See https://bugreports.qt.io/browse/QTCREATORBUG-19266 for a similar issue (using clang tooling to analyze MSVC code)

dubois avatar Apr 29 '20 00:04 dubois