Using _POSIX_SEM_VALUE_MAX not _SC_SEM_VALUE_MAX?

Paul Smith paul@mad-scientist.net
Sat Jul 8 14:43:49 GMT 2023


I have been trying to make clangd work with my GCC-based builds (it's a
long story don't ask) and after a ton of effort (and, unfortunately,
some hacks due to clangd limitations) there is one thing left that's
causing a lot of spurious errors:

In gcc/libstdc++-v3/include/bits/semaphore_base.h we find:

56  #ifdef SEM_VALUE_MAX
57      static constexpr ptrdiff_t _S_max = SEM_VALUE_MAX;
58  #else
59      static constexpr ptrdiff_t _S_max = _POSIX_SEM_VALUE_MAX;
60  #endif

Unfortunately because I am using limits.h from the clang intrinsics /
resource directory (else many other things break), _POSIX_SEM_VALUE_MAX
is not defined.  I can't quite figure out why, and my attempts to
generate preprocessor output to track it down through the #include /
#define maze have failed.  But the error I get (from clangd) suggests I
want to be using _SC_SEM_VALUE_MAX and indeed if I make that change it
works.

Should GCC be using the _SC version, since that's what's defined in
POSIX?

Or at least expanding the above to use it as a last resort, as in:

  #if defined(SEM_VALUE_MAX)
      static constexpr ptrdiff_t _S_max = SEM_VALUE_MAX;
  #elif defined(_POSIX_SEM_VALUE_MAX)
      static constexpr ptrdiff_t _S_max = _POSIX_SEM_VALUE_MAX;
  #else
      static constexpr ptrdiff_t _S_max = _SC_SEM_VALUE_MAX;
  #endif

??


More information about the Gcc mailing list