Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • G GLib
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 853
    • Issues 853
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 54
    • Merge requests 54
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GNOMEGNOME
  • GLib
  • Merge requests
  • !2578

gatomic: Add a C++ variant of g_atomic_int_compare_and_exchange()

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Philip Withnall requested to merge wip/pwithnall/2625-clang-cxx into main Apr 01, 2022
  • Overview 3
  • Commits 3
  • Pipelines 7
  • Changes 2

The C++ variant implements type safety differently, to avoid warnings from C++ compilers about:

../../../gnome-commander-1.14.2/src/intviewer/searcher.cc:303:5: error: cannot initialize a parameter of type 'gint *' (aka 'int *') with an rvalue of type 'void *'
    g_atomic_int_compare_and_exchange ((gint*)&src->priv->progress_value, oldval, (gint)d);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/mnt/b/yoe/master/build/tmp/work/cortexa72-yoe-linux/gnome-commander/1.14.2-r0/recipe-sysroot/usr/include/glib-2.0/glib/gatomic.h:160:44: note: expanded from macro 'g_atomic_int_compare_and_exchange'
    __atomic_compare_exchange_n ((atomic), (void *) (&(gaicae_oldval)), (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~

This complements the existing C++ variant for g_atomic_pointer_compare_and_exchange(), and fixes a regression on C++ from !2114 (merged).

With the addition of the unit tests in the previous commit, this is effectively tested by the FreeBSD and macOS CI jobs, as they use clang++ in C++ mode. g++ doesn’t seem to emit a warning about this.

Signed-off-by: Philip Withnall pwithnall@endlessos.org

Fixes: #2625 (closed)

Closes #2625 (closed)

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: wip/pwithnall/2625-clang-cxx