Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc.cc static_assert invalid c++11/14 on macOS #8412

Closed
zeha opened this issue Oct 13, 2019 · 3 comments · Fixed by #8413
Closed

misc.cc static_assert invalid c++11/14 on macOS #8412

zeha opened this issue Oct 13, 2019 · 3 comments · Fixed by #8413

Comments

@zeha
Copy link
Collaborator

zeha commented Oct 13, 2019

  • Program: Authoritative (but I guess all programs)
  • Issue type: Bug report

Short description

this line in misc.cc ...

    static_assert(CMSG_SPACE(sizeof(*pkt)) <= sizeof(*cmsgbuf), "Buffer is too small for in6_pktinfo");

expands to this on macOS:

    static_assert((((__darwin_size_t)((char *)(__darwin_size_t)(sizeof(struct cmsghdr)) + (sizeof(__uint32_t) - 1)) &~ (sizeof(__uint32_t) - 1)) + ((__darwin_size_t)((char *)(__darwin_size_t)(sizeof(*pkt)) + (sizeof(__uint32_t) - 1)) &~ (sizeof(__uint32_t) - 1))) <= sizeof(*cmsgbuf), "Buffer is too small for in6_pktinfo");

This apparently used to compile, but no longer does. Maybe clang got stricter about what it allows inside a constexpr. I've done a quick check if the involved header files have changed, but apparently not.

Compile failure:

misc.cc:893:19: error: static_assert expression is not an integral constant expression
    static_assert(CMSG_SPACE(sizeof(*pkt)) <= sizeof(*cmsgbuf), "Buffer is too small for in6_pktinfo");
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/socket.h:652:33: note: expanded from macro 'CMSG_SPACE'
#define CMSG_SPACE(l)           (__DARWIN_ALIGN32(sizeof(struct cmsghdr)) + __DARWIN_ALIGN32(l))
                                ^
misc.cc:893:19: note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/socket.h:652:34: note: expanded from macro 'CMSG_SPACE'
#define CMSG_SPACE(l)           (__DARWIN_ALIGN32(sizeof(struct cmsghdr)) + __DARWIN_ALIGN32(l))
                                 ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/i386/_param.h:43:42: note: expanded from macro '__DARWIN_ALIGN32'
#define       __DARWIN_ALIGN32(p)       ((__darwin_size_t)((char *)(__darwin_size_t)(p) + __DARWIN_ALIGNBYTES32) &~ __DARWIN_ALIGNBYTES32)
                                         ^
misc.cc:912:19: error: static_assert expression is not an integral constant expression
    static_assert(CMSG_SPACE(sizeof(*pkt)) <= sizeof(*cmsgbuf), "Buffer is too small for in_pktinfo");
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/socket.h:652:33: note: expanded from macro 'CMSG_SPACE'
#define CMSG_SPACE(l)           (__DARWIN_ALIGN32(sizeof(struct cmsghdr)) + __DARWIN_ALIGN32(l))
                                ^
misc.cc:912:19: note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/socket.h:652:34: note: expanded from macro 'CMSG_SPACE'
#define CMSG_SPACE(l)           (__DARWIN_ALIGN32(sizeof(struct cmsghdr)) + __DARWIN_ALIGN32(l))
                                 ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/i386/_param.h:43:42: note: expanded from macro '__DARWIN_ALIGN32'
#define       __DARWIN_ALIGN32(p)       ((__darwin_size_t)((char *)(__darwin_size_t)(p) + __DARWIN_ALIGNBYTES32) &~ __DARWIN_ALIGNBYTES32)
                                         ^
2 errors generated.

Buried in these errors is this note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression

Some info on constexpr / reinterpret_cast:
https://stackoverflow.com/questions/26200827/getting-around-the-reinterpret-cast-limitation-with-constexpr

Environment

  • Operating system: macOS Catalina
  • Software version: 37c36cc
  • Software source: git

clang version:

Apple clang version 11.0.0 (clang-1100.0.33.8)
Target: x86_64-apple-darwin19.0.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
@zeha
Copy link
Collaborator Author

zeha commented Oct 13, 2019

TBF, maybe I didn't compile master on macOS since 7f81854, but somehow I doubt this.

@zeha
Copy link
Collaborator Author

zeha commented Oct 13, 2019

@rgacogne
Copy link
Member

OK, so macOS somehow managed to implement CMSG_SPACE in a way that isn't a constexpr.. I guess we'll need to define our way out of this..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants