Source-Changes-D archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/include



On 23.05.2019 16:09, maya%netbsd.org@localhost wrote:
> On Thu, May 23, 2019 at 09:05:00AM +0200, Martin Husemann wrote:
>> On Thu, May 23, 2019 at 12:03:33AM +0200, Kamil Rytarowski wrote:
>>>>> -#if ((__cplusplus - 0) < 201103L)
>>>>> +#if defined(_ISOC11_SOURCE) || (__STDC_VERSION__ - 0) >= 201101L
>>
>> Am I missing something or does this (in addition to the intended change)
>> make the macro invisible for C++ compilations? Is that intended? If so,
>> shouldn't it be explained in the log message?
>>
>> Martin
> 
> Per the standards:
> static_assert / _Static_assert is meaningful for >=C11
> static_assert is meaningful for >=C++11
> 
>  >= C++11	: handled by libstdc++ / libc++
>  >= C11		: handled by us, in this case and before.
> 
> Should it mean something for:
>  < C++11
>  < C11
> 
> The older version attempted to provide < C++11 and < C11 static_assert,
> too.
> 
> This is causing problems because g++ does not provide _Static_assert in
> the case of building older C++ code.
> 
> Kamil argued you should just not use it if it doesn't work.
> My argument was that we shouldn't provide a broken definition.
> 
> The code from the bug report did:
> #if defined(static_assert)
> .. fallback definition ..
> #endif
> 
> I think it is reasonable for this to work.
> 
> We can probably keep providing it for all C standards, I guess. that was
> the "that's so solaris" argument. GCC does not cause problems with that.
> 

The solaris case is that we need to define very precise set of
POSIX_SOURCE/XOPEN/C_SOURCE/etc namespace, and it's difficult sometimes
to get some programs to build cleanly as there are occurrences of
missing prototypes as something is protected by a different version of
namespace. Personally, I was trying to improve SmartOS support for qemu
and fix missing prototypes, but I gave up with the maze of ifdefs.

The following patch makes static_assert functional for me for all C and
C++ standards with GCC/G++:

http://netbsd.org/~kamil/patch-00113-static_assert.txt]

It removes usage of the message command, but in practice it probably
doesn't matter. In C++17 this message argument is optional.

173 kamil@chieftec /tmp $ g++ -std=c++11 test.c
test.c: In function ‘int main(int, char**)’:
test.c:6:2: error: static assertion failed: Hello
  static_assert(sizeof(argc) == 1, "Hello");
  ^~~~~~~~~~~~~
174 kamil@chieftec /tmp $ g++ -std=c++17 test.c
test.c: In function ‘int main(int, char**)’:
test.c:6:2: error: static assertion failed: Hello
  static_assert(sizeof(argc) == 1, "Hello");
  ^~~~~~~~~~~~~
175 kamil@chieftec /tmp $ g++ -std=c++98 test.c
In file included from /usr/include/assert.h:44:0,
                 from test.c:1:
test.c: In function ‘int main(int, char**)’:
test.c:6:2: error: size of array ‘__ctassert0’ is negative
  static_assert(sizeof(argc) == 1, "Hello");

If this is fine, I will add ATF test for a combination of C and C++
standards.

Attachment: signature.asc
Description: OpenPGP digital signature



Home | Main Index | Thread Index | Old Index