C++ does not like the union { typeof(x) __val; char __c[1]; } __u construct for const types: error: uninitialized const member in 'union atomic_read(const atomic_t*)::<anonymous>' Address this by creating a C++ version of READ_ONCE where this union is initialized: union { void _u(){}; typeof(x) __val; char __c[1]; } __u={0} To please gcc 6.3.0 also add in a _u(){} as default ctor. This makes C++ happy enough to build. Signed-off-by: Joakim Tjernlund <joakim.tjernlund@xxxxxxxxxxxx> --- include/linux/compiler.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index cf0fa5d..0a047fd 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -300,6 +300,7 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s * required ordering. */ +#ifndef __cplusplus #define __READ_ONCE(x, check) \ ({ \ union { typeof(x) __val; char __c[1]; } __u; \ @@ -309,6 +310,17 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s __read_once_size_nocheck(&(x), __u.__c, sizeof(x)); \ __u.__val; \ }) +#else +#define __READ_ONCE(x, check) \ +({ \ + union { void _u(){}; typeof(x) __val; char __c[1]; } __u={0}; \ + if (check) \ + __read_once_size(&(x), __u.__c, sizeof(x)); \ + else \ + __read_once_size_nocheck(&(x), __u.__c, sizeof(x)); \ + __u.__val; \ +}) +#endif #define READ_ONCE(x) __READ_ONCE(x, 1) /* -- 2.10.2