9527 assert.h: static_assert macro should be guarded by !defined(__cplusplus)

Review Request #1084 — Created May 9, 2018 and submitted

citrus
illumos-gate
master
9527
510c7e0...
general
9527 assert.h: static_assert macro should be guarded by !defined(__cplusplus)

See issue.

Compiling simple test program with both OmniOS and pkgsrc gcc7, fails before, succeeds after.
Compared with FreeBSD header file where they guard against cplusplus - see http://src.illumos.org/source/xref/freebsd-head/include/assert.h#72

#include <cassert>
#include <cstdlib>
#include <type_traits>

int main() {}
igork
  1. Ship It!
  2. 
      
tsoome
  1. Ship It!
  2. 
      
yuripv
  1. (disclaimer: I know very little about C++)

    The comment in FreeBSD's header doesn't make much sense to me, i.e. it's not related to the checks below.

    OTOH, static_assert is defined for C++ >= C11 (http://en.cppreference.com/w/cpp/language/static_assert).

    1. Erm, I mean C++11, of course.

    2. It seems that static_assert via _Static_assert is a C11 thing, not C++11.. C++11 just uses static_assert() as per your link.

      The C equivalent is here http://en.cppreference.com/w/c/error/static_assert

      #define static_assert _Static_assert
      
      static_assert(2 + 2 == 4, "2+2 isn't 4");
      

      So the definition should just apply to C, hence this change. I agree that the comment in FreeBSD makes no sense (well, the second half does, just not the first).

    3. Yes, makes sense (forgot to click "ship it").

  2. 
      
rm
  1. Ship It!
  2. 
      
yuripv
  1. Ship It!
  2. 
      
citrus
Review request changed

Status: Closed (submitted)

Loading...