Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1585431
| From | Joakim Tjernlund <joakim.tjernlund@infinera.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 2/2] compiler.h: fix C++ uninitialized const issue |
| Date | 2017-02-21 16:40 +0100 |
| Message-ID | <tdkHN-4r9-53@gated-at.bofh.it> (permalink) |
| References | <tdkHM-4r9-27@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
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@infinera.com>
---
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
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 1/2] Correct function definition for C++ Joakim Tjernlund <joakim.tjernlund@infinera.com> - 2017-02-21 16:40 +0100
[PATCH 2/2] compiler.h: fix C++ uninitialized const issue Joakim Tjernlund <joakim.tjernlund@infinera.com> - 2017-02-21 16:40 +0100
Re: [PATCH 1/2] Correct function definition for C++ Greg KH <greg@kroah.com> - 2017-02-22 08:20 +0100
Re: [PATCH 1/2] Correct function definition for C++ "greg@kroah.com" <greg@kroah.com> - 2017-02-22 14:10 +0100
Re: [PATCH 1/2] Correct function definition for C++ "greg@kroah.com" <greg@kroah.com> - 2017-02-22 15:30 +0100
Re: [PATCH 1/2] Correct function definition for C++ Thomas Backlund <tmb@mageia.org> - 2017-03-01 02:00 +0100
csiph-web