On 2017-Aug-25, at 12:14 AM, David Chisnall <theraven at FreeBSD.org> wrote:

> On 25 Aug 2017, at 07:32, Mark Millard <markmi at dsl-only.net> wrote:
>> As I remember _Static_assert is from C11, not
>> the older C99.
> In pre-C11 dialects of C, _Static_assert is an identifier reserved for the 
> implementation.  sys/cdefs.h defines it to generate a zero-length array if 
> the condition is true or a negative-length array if it is false, emulating 
> the behaviour (though giving less helpful error messages)
>> As I understand head/sys/dev/nvme/nvme.h use by
>> C++ code could now reject attempts to use
>> _Static_assert .
> In C++, _Static_assert is an identifier reserved for the implementation, but 
> in C++11 or newer static_assert is a keyword.  sys/cdefs.h defines 
> _Static_assert to static_assert for newer versions of C++ and defines it to 
> the C-before-11-compatible version for C++-before-11.
> TL;DR: We have gone to a lot of effort to ensure that these keywords work in 
> all C/C++ dialects, please use them, please report bugs if you find a case 
> where they don’t work.

It appears that at least 11.1-STABLE -r322807 does not handle
-std=c++98 styles of use of _Static_assert for g++7 in that
g++7 reports an error:

# uname -apKU
FreeBSD hzFreeBSD11S 11.1-STABLE FreeBSD 11.1-STABLE  r322807  amd64 amd64 
1101501 1101501

# more main.cc
#include "/usr/include/sys/cdefs.h"
int main(void)
   return 0;

# g++7 -std=c++98 main.cc
main.cc:2:15: error: expected constructor, destructor, or type conversion 
before '(' token

So it appears that as stands the _Static_assert
implementation requires a more modern C++ standard

With the likes of -Wpedantic clang++ from 11.1-STABLE
-r322807 reports a warning:

# clang++ -Wpedantic -std=c++11 main.cc
main.cc:2:1: warning: _Static_assert is a C11-specific feature 
1 warning generated.

# clang++ -Wpedantic -std=c++98 main.cc
In file included from main.cc:1:
/usr/include/sys/cdefs.h:852:27: warning: variadic macros are a C99 feature 
#define __locks_exclusive(...) \
. . . (more such macro reports) . . .
main.cc:2:1: warning: _Static_assert is a C11-specific feature 
11 warnings generated.

By contrast "g++7 -Wpedantic -std=c++11 main.cc" is silent about it.

Mark Millard
markmi at dsl-only.net

freebsd-current@freebsd.org mailing list
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"

Reply via email to