WKDSMRT / realsense-gstreamer

GStreamer source plugin for the Intel RealSense line of cameras
GNU Lesser General Public License v3.0
30 stars 13 forks source link

error: argument 2 of ‘__atomic_load’ must not be a pointer to a ‘volatile’ type #28

Open arielmol opened 10 months ago

arielmol commented 10 months ago

As per requirements "GStreamer 1.0 or higher", I tried with v1.16.

gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04)

$  ninja -C build 
ninja: Entering directory `build'
[1/4] Compiling C++ object src/libgstrealsense_meta.so.p/gstrealsensemeta.cpp.o
FAILED: src/libgstrealsense_meta.so.p/gstrealsensemeta.cpp.o 
c++ -Isrc/libgstrealsense_meta.so.p -Isrc -I../src -I/usr/include/gstreamer-1.0 -I/usr/include/x86_64-linux-gnu -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/orc-0.4 -I/usr/local/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -O0 -g -fPIC -pthread -MD -MQ src/libgstrealsense_meta.so.p/gstrealsensemeta.cpp.o -MF src/libgstrealsense_meta.so.p/gstrealsensemeta.cpp.o.d -o src/libgstrealsense_meta.so.p/gstrealsensemeta.cpp.o -c ../src/gstrealsensemeta.cpp
In file included from /usr/include/glib-2.0/glib/gthread.h:32,
                 from /usr/include/glib-2.0/glib/gasyncqueue.h:32,
                 from /usr/include/glib-2.0/glib.h:32,
                 from /usr/include/gstreamer-1.0/gst/gst.h:27,
                 from ../src/gstrealsensemeta.cpp:21:
../src/gstrealsensemeta.cpp: In function ‘GType gst_realsense_meta_api_get_type()’:
/usr/include/glib-2.0/glib/gatomic.h:113:19: error: argument 2 of ‘__atomic_load’ must not be a pointer to a ‘volatile’ type
  113 |     __atomic_load (gapg_temp_atomic, &gapg_temp_newval, __ATOMIC_SEQ_CST); \
      |     ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gthread.h:260:7: note: in expansion of macro ‘g_atomic_pointer_get’
  260 |     (!g_atomic_pointer_get (location) &&                             \
      |       ^~~~~~~~~~~~~~~~~~~~
../src/gstrealsensemeta.cpp:34:9: note: in expansion of macro ‘g_once_init_enter’
   34 |     if (g_once_init_enter (&type)) {
      |         ^~~~~~~~~~~~~~~~~
ninja: build stopped: subcommand failed.
arielmol commented 10 months ago

Just by removing volatile from https://github.com/WKDSMRT/realsense-gstreamer/blob/4c11e3d64ae67fea84db77145743db8522d3989a/src/gstrealsensemeta.cpp#L32

It builds cleanly, but I wonder the side effects of that?

arielmol commented 10 months ago

Quoting Philip Chimento from here:

On platforms where g_once_init_enter() is defined to use C11 atomic builtins, passing a pointer to a volatile value is an error in GCC 11 and later, in C++.

More info about the GCC change: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95378 https://gcc.gnu.org/pipermail/gcc-patches/2020-June/548283.html

However, it's my understanding that in modern C++ there is no longer a need to guard the initialization of these variables. Since C++11, static local variables in a function are guaranteed to be initialized only once, the first time control passes through that function. So we can just remove the g_once_init_enter guard.

So it seems if C++11 is used, then volatile is not needed or g_once_init_enter is not needed? I dont get it.

reidaruss commented 8 months ago

Did you fix this? I'm also on gcc 11.4.0 and am getting the same error, so is this a C++ 11 vs C++ 17 issue?