This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 2fa607796d5 include/nuttx/atomic.h: Fix C++ compilation with 
-nostdinc++
2fa607796d5 is described below

commit 2fa607796d5869f84a9fd24b437c2b39227c5a48
Author: Jukka Laitinen <jukka.laiti...@tii.ae>
AuthorDate: Tue Aug 5 17:15:24 2025 +0300

    include/nuttx/atomic.h: Fix C++ compilation with -nostdinc++
    
    Without c++ standard includes, the <atomic> library is not available.
    GCC may use __auto_type for the C-style atomic oprations, and this
    is not available for C++. Just define the __auto_type to auto for C++.
    
    Also, the built-in _atomic functions for GCC expect "volatile" parameters
    in C, but don't allow that in C++. So selecting the atomic_t and atomic64_t
    types according to that.
    
    Signed-off-by: Jukka Laitinen <jukka.laiti...@tii.ae>
---
 include/nuttx/atomic.h | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/include/nuttx/atomic.h b/include/nuttx/atomic.h
index 53b24b02a11..79d475f0189 100644
--- a/include/nuttx/atomic.h
+++ b/include/nuttx/atomic.h
@@ -60,8 +60,14 @@ extern "C++"
 #    include <stdatomic.h>
 #    define ATOMIC_FUNC(f, n) atomic_##f##_explicit
 
-  typedef volatile _Atomic int32_t atomic_t;
-  typedef volatile _Atomic int64_t atomic64_t;
+#    if defined(__cplusplus)
+#      define __auto_type auto
+typedef _Atomic int32_t atomic_t;
+typedef _Atomic int64_t atomic64_t;
+#    else
+typedef volatile _Atomic int32_t atomic_t;
+typedef volatile _Atomic int64_t atomic64_t;
+#    endif
 #  endif
 #endif
 

Reply via email to