[PATCH] uapi: partially fix __DECLARE_FLEX_ARRAY for C++

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


__DECLARE_FLEX_ARRAY(T, member) macro expands to

	struct {
		struct {} __empty_member;
		T member[];

which is subtly wrong in C++ because sizeof(struct{}) is 1 not 0,
changing UAPI structures layouts.

This can be fixed by expanding simply to

	T member[];

Most of the usages still be broken because of other C++ shenanigans
but this fixes simplest usage: 1 flexible member at the end.

Fix header guard while I'm at it.

Signed-off-by: Alexey Dobriyan <adobriyan@xxxxxxxxx>

 include/uapi/linux/stddef.h |    6 ++++++
 1 file changed, 6 insertions(+)

--- a/include/uapi/linux/stddef.h
+++ b/include/uapi/linux/stddef.h
@@ -39,6 +39,10 @@
  * struct, it needs to be wrapped in an anonymous struct with at least 1
  * named member, but that member can be empty.
+#ifdef __cplusplus
+#define __DECLARE_FLEX_ARRAY(T, member)		\
+	T member[]
 	struct { \
 		struct { } __empty_ ## NAME; \
@@ -49,3 +53,5 @@
 #ifndef __counted_by
 #define __counted_by(m)

[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux