Fix order of initializers in CDS_LIST_HEAD_INIT
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 8 Sep 2021 19:30:28 +0000 (15:30 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 8 Sep 2021 19:30:28 +0000 (15:30 -0400)
When using CDS_LIST_HEAD_INIT in a C++ program, we get (with clang
rather than gcc, because the error message is clearer):

    /home/simark/src/urcu/tests/unit/test_build_cxx.cpp:73:13: error: ISO C++ requires field designators to be specified in declaration order; field 'prev' will be initialized after field 'next' [-Werror,-Wreorder-init-list]
        .head = CDS_LIST_HEAD_INIT(list.head),
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/simark/src/urcu/include/urcu/list.h:49:53: note: expanded from macro 'CDS_LIST_HEAD_INIT'
    #define CDS_LIST_HEAD_INIT(name) { .prev = &(name), .next = &(name) }
                                                        ^~~~~~~~~~~~~~~
    /home/simark/src/urcu/tests/unit/test_build_cxx.cpp:73:13: note: previous initialization for field 'prev' is here
        .head = CDS_LIST_HEAD_INIT(list.head),
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/simark/src/urcu/include/urcu/list.h:49:44: note: expanded from macro 'CDS_LIST_HEAD_INIT'
    #define CDS_LIST_HEAD_INIT(name) { .prev = &(name), .next = &(name) }
                                               ^~~~~~~

Fix that by swapping the initializers in CDS_LIST_HEAD_INIT.

Change-Id: Ib127b9cc128fd64f5b2ae028e093be42ca10f437
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/urcu/list.h

index f3b867839030fb3ceeda4192f2c0f4c20b856971..8cfbd8462d97abe11b9ca5af9f80e0b15b221ab9 100644 (file)
@@ -46,7 +46,7 @@ struct cds_list_head {
 #define CDS_INIT_LIST_HEAD(ptr) \
        (ptr)->next = (ptr)->prev = (ptr)
 
-#define CDS_LIST_HEAD_INIT(name) { .prev = &(name), .next = &(name) }
+#define CDS_LIST_HEAD_INIT(name) { .next = &(name), .prev = &(name) }
 
 /* Add new element at the head of the list. */
 static inline
This page took 0.026338 seconds and 4 git commands to generate.