Skip to content

Fix GCC 9.4 build: gate std::atomic<shared_ptr> on C++20 feature macro#287

Open
jfsantos wants to merge 1 commit into
sdatkinson:mainfrom
jfsantos:fix/gcc94-atomic-shared-ptr
Open

Fix GCC 9.4 build: gate std::atomic<shared_ptr> on C++20 feature macro#287
jfsantos wants to merge 1 commit into
sdatkinson:mainfrom
jfsantos:fix/gcc94-atomic-shared-ptr

Conversation

@jfsantos

Copy link
Copy Markdown
Contributor

Problem

This project fails to build under GCC 9.4.0 because NAM/wavenet/slimmable.h uses std::atomic<std::shared_ptr<T>>, a C++20 library feature that libstdc++ only supports from GCC 12.

The header already had a fallback to the deprecated std::atomic_* free-function overloads for shared_ptr, but it was keyed on #ifdef _LIBCPP_VERSION. GCC 9.4 uses libstdc++ (not libc++), so it took the #else branch and required the unsupported std::atomic<std::shared_ptr<>>.

Fix

Key the selection on the standard C++20 feature-test macro __cpp_lib_atomic_shared_ptr instead of on a specific standard library:

#if defined(__cpp_lib_atomic_shared_ptr) && __cpp_lib_atomic_shared_ptr >= 201711L
  #define NAM_HAS_ATOMIC_SHARED_PTR 1
#else
  #define NAM_HAS_ATOMIC_SHARED_PTR 0
#endif
  • GCC 12+ (macro defined) → unchanged, uses the member std::atomic<std::shared_ptr<>> path.
  • libc++ (macro never defined — feature still unimplemented) → unchanged, uses the free-function fallback exactly as before.
  • GCC 9.4 + libstdc++ (macro undefined) → now correctly takes the free-function fallback instead of failing to compile.

No behavior change for any compiler that previously built.

Files changed

  • NAM/wavenet/slimmable.h — feature-macro guard, conditional include, member declaration.
  • NAM/wavenet/slimmable.cpp — the four staging accessor definitions.

std::atomic<std::shared_ptr<T>> is a C++20 library feature that libstdc++
only supports from GCC 12. The fallback to the deprecated std::atomic_*
free-function overloads was keyed on _LIBCPP_VERSION, so GCC 9.4 (libstdc++,
not libc++) took the unsupported branch and failed to compile.

Key the selection on the standard __cpp_lib_atomic_shared_ptr feature-test
macro instead. It is undefined on both libc++ and pre-12 libstdc++, routing
both to the free-function fallback, and defined on GCC 12+ where the member
std::atomic<std::shared_ptr> path is used. No behavior change for any
compiler that previously built.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant