[newlib-cygwin] Fix C++ includability of crypto headers with static array sizes

Corinna Vinschen corinna@sourceware.org
Tue Apr 4 09:44:00 GMT 2017


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=84a6dba57ed351a275889a3e8c87f566e3b3e508

commit 84a6dba57ed351a275889a3e8c87f566e3b3e508
Author: asomers <asomers@FreeBSD.org>
Date:   Tue Apr 4 09:04:54 2017 +0200

    Fix C++ includability of crypto headers with static array sizes
    
    C99 allows array function parameters to use the static keyword for their
    sizes. This tells the compiler that the parameter will have at least the
    specified size, and calling code will fail to compile if that guarantee is
    not met. However, this syntax is not legal in C++.
    
    This commit reverts r300824, which worked around the problem for
    sys/md5.h only, and introduces a new macro: min_size(). min_size(x) can
    be used in headers as a static array size, but will still compile in C++
    mode.
    
    Reviewed by:	cem, ed
    MFC after:	4 weeks
    Sponsored by:	Spectra Logic Corp
    Differential Revision:	https://reviews.freebsd.org/D8277
    
    fix a typo in __STDC_VERSION__ in __min_size requirements
    
    MFC after:	1 week
    Sponsored by:	Panzura

Diff:
---
 newlib/libc/include/sys/cdefs.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h
index 0c8fced..68172ad 100644
--- a/newlib/libc/include/sys/cdefs.h
+++ b/newlib/libc/include/sys/cdefs.h
@@ -361,6 +361,20 @@
 	    __builtin_types_compatible_p(__typeof(expr), t), yes, no)
 #endif
 
+/*
+ * C99 Static array indices in function parameter declarations.  Syntax such as:
+ * void bar(int myArray[static 10]);
+ * is allowed in C99 but not in C++.  Define __min_size appropriately so
+ * headers using it can be compiled in either language.  Use like this:
+ * void bar(int myArray[__min_size(10)]);
+ */
+#if !defined(__cplusplus) && \
+    (!defined(__STDC_VERSION__) || (__STDC_VERSION__ >= 199901))
+#define __min_size(x)	static (x)
+#else
+#define __min_size(x)	(x)
+#endif
+
 #if __GNUC_PREREQ__(2, 96)
 #define	__malloc_like	__attribute__((__malloc__))
 #define	__pure		__attribute__((__pure__))



More information about the Newlib-cvs mailing list