https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121373

            Bug ID: 121373
           Summary: std::byte_swap is not available when using import std
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: printfne at gmail dot com
  Target Milestone: ---

/// main.cpp It works properly when include<bit> is used
#include <bit>
int main() {
    static_assert(std::byteswap((unsigned short)0x00ff) == (unsigned
short)0xff00 );
    return 0;
}

/// main.cpp An error will be obtained when using import std
import std;
int main() {
    static_assert(std::byteswap((unsigned short)0x00ff) == (unsigned
short)0xff00 );
    return 0;
}

/// Compilation command
g++-latest -std=gnu++26 -c -fmodules -fsearch-include-path bits/std.cc
g++-latest -std=gnu++26 -fmodules main.cpp   

/// error message
main.cpp: In function 'int main()':
main.cpp:5:24: error: 'byteswap' is not a member of 'std'
    5 |     static_assert(std::byteswap((unsigned short)0x00ff) == (unsigned
short)0xff00 );
      |    

/// 
I provided a patch for this issue and sent it to gcc-patc...@gcc.gnu.org, cc to
jwak...@redhat.com. But no response was received.
For some reasons, I couldn't find this patch in the short term. Displaying the
email content seems to be a feasible solution

/// title
[PATCH] libstdc++: Export std::byteswap from std.cc.in

/// content
After import std, std::byteswap cannot be used.
After my observation, this function is the only one in the <bit> header file
that has not been exported.
The purpose of this patch is to export std::byteswap so that it can be used
normally after import std.

Signed-off-by: hexne <61956889+he...@users.noreply.github.com>
---
 libstdc++-v3/src/c++23/std.cc.in | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libstdc++-v3/src/c++23/std.cc.in
b/libstdc++-v3/src/c++23/std.cc.in
index 9301ed90c00..61f0b715b36 100644
--- a/libstdc++-v3/src/c++23/std.cc.in
+++ b/libstdc++-v3/src/c++23/std.cc.in
@@ -663,6 +663,7 @@ export namespace std
   using std::bit_ceil;
   using std::bit_floor;
   using std::bit_width;
+  using std::byteswap;
   using std::countl_one;
   using std::countl_zero;
   using std::countr_one;
-- 

This issue should be very easy for anyone to fix, but if possible, I really
hope to know how to write this patch email and see that I have successfully
submitted the patch to gcc. Thanks.

Reply via email to