Fix GCC 9.4 build: gate std::atomic<shared_ptr> on C++20 feature macro#287
Open
jfsantos wants to merge 1 commit into
Open
Fix GCC 9.4 build: gate std::atomic<shared_ptr> on C++20 feature macro#287jfsantos wants to merge 1 commit into
jfsantos wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
This project fails to build under GCC 9.4.0 because
NAM/wavenet/slimmable.husesstd::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 forshared_ptr, but it was keyed on#ifdef _LIBCPP_VERSION. GCC 9.4 uses libstdc++ (not libc++), so it took the#elsebranch and required the unsupportedstd::atomic<std::shared_ptr<>>.Fix
Key the selection on the standard C++20 feature-test macro
__cpp_lib_atomic_shared_ptrinstead of on a specific standard library:std::atomic<std::shared_ptr<>>path.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.