CoatiSoftware / vs-sourcetrail

Visual Studio Extension to communicate with Sourcetrail and generate a JSON Compilation Database from a Visual Studio Solution
Apache License 2.0
117 stars 42 forks source link

"offsetof" errors when indexing #68

Open dubois opened 4 years ago

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

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