[1/6] Make _Static_assert() work with GCC in older C++ standards.

Message ID 20180727074042.23644-1-sebastian.huber@embedded-brains.de
State Accepted
Commit 84e294dc694257d8f3e9b00a4a0651afbf76132a
Headers show
Series
  • [1/6] Make _Static_assert() work with GCC in older C++ standards.
Related show

Commit Message

Sebastian Huber July 27, 2018, 7:40 a.m.
From: "ed@FreeBSD.org" <ed@FreeBSD.org>


GCC only activates C11 keywords in C mode, not C++ mode. This means
that when targeting an older C++ standard, we cannot fall back to using
_Static_assert(). In this case, do define _Static_assert() as a macro
that uses a typedef'ed array.

Discussed in:	r322875 commit thread
Reported by:	Mark MIllard
MFC after:	1 month
---
 newlib/libc/include/sys/cdefs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.13.7

Comments

Corinna Vinschen July 30, 2018, 7:50 a.m. | #1
On Jul 27 09:40, Sebastian Huber wrote:
> From: "ed@FreeBSD.org" <ed@FreeBSD.org>

> 

> GCC only activates C11 keywords in C mode, not C++ mode. This means

> that when targeting an older C++ standard, we cannot fall back to using

> _Static_assert(). In this case, do define _Static_assert() as a macro

> that uses a typedef'ed array.

> 

> Discussed in:	r322875 commit thread

> Reported by:	Mark MIllard

> MFC after:	1 month

> ---

>  newlib/libc/include/sys/cdefs.h | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)

> 

> diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h

> index b3f8d1965..49be9e062 100644

> --- a/newlib/libc/include/sys/cdefs.h

> +++ b/newlib/libc/include/sys/cdefs.h

> @@ -314,7 +314,7 @@

>  #if (defined(__cplusplus) && __cplusplus >= 201103L) || \

>      __has_extension(cxx_static_assert)

>  #define	_Static_assert(x, y)	static_assert(x, y)

> -#elif __GNUC_PREREQ__(4,6)

> +#elif __GNUC_PREREQ__(4,6) && !defined(__cplusplus)

>  /* Nothing, gcc 4.6 and higher has _Static_assert built-in */

>  #elif defined(__COUNTER__)

>  #define	_Static_assert(x, y)	__Static_assert(x, __COUNTER__)

> -- 

> 2.13.7


ACK to series.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

Patch

diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h
index b3f8d1965..49be9e062 100644
--- a/newlib/libc/include/sys/cdefs.h
+++ b/newlib/libc/include/sys/cdefs.h
@@ -314,7 +314,7 @@ 
 #if (defined(__cplusplus) && __cplusplus >= 201103L) || \
     __has_extension(cxx_static_assert)
 #define	_Static_assert(x, y)	static_assert(x, y)
-#elif __GNUC_PREREQ__(4,6)
+#elif __GNUC_PREREQ__(4,6) && !defined(__cplusplus)
 /* Nothing, gcc 4.6 and higher has _Static_assert built-in */
 #elif defined(__COUNTER__)
 #define	_Static_assert(x, y)	__Static_assert(x, __COUNTER__)