erofs-utils: fix "non-trivial designated initializers not supported"
authorGao Xiang <hsiangkao@linux.alibaba.com>
Thu, 27 Jun 2024 03:13:43 +0000 (11:13 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Thu, 27 Jun 2024 03:21:00 +0000 (11:21 +0800)
This partially reverts commit 79f6e168d94c ("erofs-utils: improve
compatibility and reduce header conflicts") since some C++ compiler
will complain:

include/erofs_fs.h: In function 'void erofs_check_ondisk_layout_definitions()':
include/erofs_fs.h:460:2: sorry, unimplemented: non-trivial designated initializers not supported

Let's just bypass this compile-time check for the C++ language since
only external programs may be written in C++.

Fixes: 79f6e168d94c ("erofs-utils: improve compatibility and reduce header conflicts")
Cc: Hongzhen Luo <hongzhen@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240627031343.3424030-1-hsiangkao@linux.alibaba.com
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
include/erofs_fs.h

index 0d603c4872ea4416ac6953b265b7f336c759d2d6..fc21915299b259d039c29604f292c2019f3e49bb 100644 (file)
@@ -450,14 +450,14 @@ struct z_erofs_lcluster_index {
 /* check the EROFS on-disk layout strictly at compile time */
 static inline void erofs_check_ondisk_layout_definitions(void)
 {
+#ifndef __cplusplus
        const union {
                struct z_erofs_map_header h;
                __le64 v;
        } fmh __maybe_unused = {
-               .h = {
-                       .h_clusterbits = 1 <<Z_EROFS_FRAGMENT_INODE_BIT,
-               },
+               .h.h_clusterbits = 1 << Z_EROFS_FRAGMENT_INODE_BIT,
        };
+#endif
 
        BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128);
        BUILD_BUG_ON(sizeof(struct erofs_inode_compact) != 32);
@@ -476,9 +476,11 @@ static inline void erofs_check_ondisk_layout_definitions(void)
 
        BUILD_BUG_ON(BIT(Z_EROFS_LI_LCLUSTER_TYPE_BITS) <
                     Z_EROFS_LCLUSTER_TYPE_MAX - 1);
+#ifndef __cplusplus
        /* exclude old compiler versions like gcc 7.5.0 */
        BUILD_BUG_ON(__builtin_constant_p(fmh.v) ?
                     fmh.v != cpu_to_le64(1ULL << 63) : 0);
+#endif
 }
 
 #endif