tech-userlevel archive

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

Re: static_assert



On 22.05.2019 13:44, maya%netbsd.org@localhost wrote:
> This is definition is causing problems.

Please fix Perl to stop mixing C11 with C++98 code.

This is designed (discussed and approved by Joerg) to be an extension,
similarly to the code in <stdalign.h>. We explicitly allow mixing
features from newer standards of C and C++ in code in older ones,
whenever it is supported by a compiler. If it is not supported or not
handled, it's not our fault, but fault of a user.

"clang++ -ansi" ships with _Static_assert, "g++ -ansi" doesn't.

It's fine to use static_assert and detect if it is a C11 macro... but
before using it, it shall be tested by autoconf/similar.

Perl's broken feature detection caused issued also for others, at least
on IBM compiler and received a special case handling.

I propose the following patch:

-#if (defined(static_assert) || (defined(__cplusplus) && __cplusplus >=
201103L)) && (!defined(__IBMC__) || __IBMC__ >= 1210)
+#if ((defined(static_assert) && (__STDC_VERSION__ - 0) >= 201101L) ||
(defined(__cplusplus) && __cplusplus >= 201103L)) && (!defined(__IBMC__)
|| __IBMC__ >= 1210)

> Bug report: https://rt.perl.org/Ticket/Display.html?id=134023
> 
> Standalone test case:
> #!/bin/sh
> 
> cat << EOF > AAAtest.cpp
> #include <assert.h>
> #ifndef static_assert
> #define static_assert theoretical fallback definition that doesnt happen
> #endif
> 
> int main() {
> 	static_assert(sizeof(int) < sizeof(char), "some assertion");
> 	return 0;
> }
> EOF
> c++ -ansi AAAtest.cpp
> 
> ----- Forwarded message from Kamil Rytarowski <kamil%netbsd.org@localhost> -----
> 
> Date: Mon, 3 Oct 2016 12:08:39 +0000
> From: Kamil Rytarowski <kamil%netbsd.org@localhost>
> To: source-changes-full%NetBSD.org@localhost
> Subject: CVS commit: src/include
> X-Mailer: log_accum
> 
> Module Name:	src
> Committed By:	kamil
> Date:		Mon Oct  3 12:08:39 UTC 2016
> 
> Modified Files:
> 	src/include: assert.h
> 
> Log Message:
> Add static_assert macro definition in <assert.h>
> 
> This declaration conforms to the C11 standard
> Reference: ISO/IEC 9899:201x 7.2 Diagnostics <assert.h>
> 
> _Static_assert performs compile-time assertion checking.
> 
> According to ISO/IEC 9899:201x (draft) 7.2 Diagnostics <assert.h> defines
> the static_assert macro which expands to _Static_assert. It's not
> conditionalized by NDEBUG like the assert macro.
> 
> According to ISO/IEC N3242=11-0012 (C++1x) the <cassert> header shall
> define only the assert macro, but not static_assert as it's already part
> of the C++11 language.
> 
> Allow to define static_assert in C++ prior the C++11 standard. It might be
> broken but a nonstandard C++ compiler might support C11-like _Static_assert
> feature. Note that it's fatal for g++ 5.4, but it works for clang++ 3.8.1.
> 
> Approved by <joerg>.
> 
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.21 -r1.22 src/include/assert.h
> 
> Please note that diffs are not public domain; they are subject to the
> copyright notices on the relevant files.
> 
> 
> Modified files:
> 
> Index: src/include/assert.h
> diff -u src/include/assert.h:1.21 src/include/assert.h:1.22
> --- src/include/assert.h:1.21	Fri Aug 26 01:10:49 2011
> +++ src/include/assert.h	Mon Oct  3 12:08:39 2016
> @@ -1,4 +1,4 @@
> -/*	$NetBSD: assert.h,v 1.21 2011/08/26 01:10:49 joerg Exp $	*/
> +/*	$NetBSD: assert.h,v 1.22 2016/10/03 12:08:39 kamil Exp $	*/
>  
>  /*-
>   * Copyright (c) 1992, 1993
> @@ -104,3 +104,9 @@ void __diagassert(const char *, int, con
>  void __diagassert13(const char *, int, const char *, const char *);
>  __END_DECLS
>  #endif /* __ASSERT_DECLARED */
> +
> +#if ((__cplusplus - 0) < 201103L)
> +#ifndef static_assert
> +#define static_assert _Static_assert
> +#endif /* static_assert */
> +#endif
> 
> 
> 
> ----- End forwarded message -----
> 


Attachment: signature.asc
Description: OpenPGP digital signature



Home | Main Index | Thread Index | Old Index