Add C++ build tests
authorSimon Marchi <simon.marchi@polymtl.ca>
Thu, 29 Jul 2021 02:48:21 +0000 (22:48 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 8 Sep 2021 19:28:38 +0000 (15:28 -0400)
commit2875743718fb23293190b5edd0f2b530977270b1
tree9a89de97211dd354e916e66e4deb5580e1589c81
parent153b081a9b007aad7bece415dc3bf1125edd2da3
Add C++ build tests

Some urcu header files cause build failures when included in C++
programs.  Add a test file that includes all exported headers (except
those that are marked as deprecated) and build that test file as a C and
C++ program, with and without _LGPL_SOURCE defined (to test both the
static and non-static implementations).  This helps ensure that the code
in these headers works as both languages.  This alone does not ensure
full coverage, there may be code in unused macros that would need
fixing.  But by including the "static" headers, this already finds a few
issues.

The test doesn't run anything, its purpose is only to verify that things
build.

This catches the following build failures:

 - clang++ doesn't know the __transparent_union__ attribute, place some
   pragmas to ignore this warning around where __transparent_union__ is
   used.

 - CDS_WFS_WOULDBLOCK and CDS_WFS_END are cast to a void*.  This doesn't
   work in C++ when assigning to a field them to typed pointer.  Fix
   them by casting to the appropriate type.

 - The transparent union trick doesn't work in C++:

      CXX      test_build_cxx.o
    In file included from /home/simark/src/urcu/include/urcu/wfstack.h:116,
                     from /home/simark/src/urcu/include/urcu/cds.h:35,
                     from /home/simark/src/urcu/tests/unit/test_build_cxx.cpp:34:
    /home/simark/src/urcu/include/urcu/static/wfstack.h: In function ‘cds_wfs_node* _cds_wfs_pop_with_state_blocking(cds_wfs_stack*, int*)’:
    /home/simark/src/urcu/include/urcu/static/wfstack.h:350:54: error: could not convert ‘s’ from ‘cds_wfs_stack*’ to ‘cds_wfs_stack_ptr_t’
      350 |         retnode = ___cds_wfs_pop_with_state_blocking(s, state);
          |                                                      ^
          |                                                      |
          |                                                      cds_wfs_stack*

   A C++ user can fall back to instantiating a cds_wfs_stack_ptr_t
   explicitly, assigning the right field, and passing the
   cds_wfs_stack_ptr_t to the function.  Fix a few instances in the
   static headers.

   A follow up commit will introduce C++ API wrappers based on
   function overloading to provide a C++ API similar to the C API.

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I30adc8df69414a0a019c5ec081f64cfac64843f5
include/urcu/compiler.h
include/urcu/lfstack.h
include/urcu/static/lfstack.h
include/urcu/static/rculfqueue.h
include/urcu/static/wfstack.h
include/urcu/wfstack.h
tests/unit/Makefile.am
tests/unit/test_build.c [new file with mode: 0644]
tests/unit/test_build_cxx.cpp [new file with mode: 0644]
This page took 0.026719 seconds and 4 git commands to generate.