[glib: 1/2] Avoid C++20 deprecated assignment to volatile



commit 3e4bca79ff3f021b7f24da06e41b9f0ee062c254
Author: Stephan Bergmann <sbergman redhat com>
Date:   Thu Oct 17 11:36:50 2019 +0200

    Avoid C++20 deprecated assignment to volatile
    
    794c1a30bc27b4c8d77537813acb1213d5ac80f2 "macro wrappers for
    g_once_init_enter/leave" added this line (whose intent is unclear to me).
    
    <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1152r4.html>
    "Deprecating volatile" (scheduled for inclusion in C++20) will make the
    assignment expression
    
      *(location) = (result)
    
    deprecated when the LHS is of (non-class) volatile type, which is the case when
    g_once_init_leave is expanded as part of e.g. G_DEFINE_TYPE_WITH_CODE (in
    gobject/gtype.h), where location is a pointer to some
    
      static volatile gsize g_define_type_id__volatile = 0;
    
    Recent Clang trunk emits -Wdeprecated-volatile for it under -std=c++2a since
    <https://github.com/llvm/llvm-project/commit/
    4a6861a7e5b59be24a09b8b9782255d028e7aade> "[c++20] P1152R4: warn on any
    simple-assignment to a volatile lvalue".
    
    The fix is to make the assignment expression a discared-value expression by
    casting it to void (which in turn requires casting the second branch of the
    surrounding conditional expression to void, too; not sure what the top-level
    cast to void was intended for, and whether it would still be needed under
    certain circumstances).

 glib/gthread.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
---
diff --git a/glib/gthread.h b/glib/gthread.h
index 375771ad4..366b0ad67 100644
--- a/glib/gthread.h
+++ b/glib/gthread.h
@@ -254,7 +254,7 @@ void            g_once_init_leave               (volatile void  *location,
 # define g_once_init_leave(location, result) \
   (G_GNUC_EXTENSION ({                                               \
     G_STATIC_ASSERT (sizeof *(location) == sizeof (gpointer));       \
-    (void) (0 ? *(location) = (result) : 0);                         \
+    0 ? (void) (*(location) = (result)) : (void) 0;                  \
     g_once_init_leave ((location), (gsize) (result));                \
   }))
 #else


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]