Fix std::byte namespace declaration

Message ID 854ca186-bdfb-2ed1-4623-af0ad1ca433c@gmail.com
State New
Headers show
Series
  • Fix std::byte namespace declaration
Related show

Commit Message

François Dumont Oct. 18, 2018, 8:12 p.m.
Current build of libstdc++ with --enable-symvers=gnu-versioned-namespace 
fails (at least under Linux) because of:

In file included from 
/home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/memory_resource:39,
                  from 
../../../../../git/libstdc++-v3/src/c++17/memory_resource.cc:25:
/home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/cstddef:71:59: 
error: la référence à « byte » est ambiguë
    71 |   template<> struct __byte_operand<bool> { using __type = byte; };
       | ^~~~
In file included from 
/home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/stl_algobase.h:61,
                  from 
/home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/memory:62,
                  from 
/home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/memory_resource:37,
                  from 
../../../../../git/libstdc++-v3/src/c++17/memory_resource.cc:25:
/home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/cpp_type_traits.h:395:30: 
note: les candidats sont : « enum class std::__8::byte »
   395 |   enum class byte : unsigned char;
       |                              ^~~~
In file included from 
/home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/memory_resource:39,
                  from 
../../../../../git/libstdc++-v3/src/c++17/memory_resource.cc:25:
/home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/cstddef:68:14: 
note:                      « enum class std::byte »
    68 |   enum class byte : unsigned char {};
       |              ^~~~

I think the issue if that std::byte declaration in cpp_type_traits.h has 
been done in versioned namespace, so the attached patch.

     * include/bits/cpp_type_traits.h (std::byte): Move outside versioned
     namespace.

Tested under Linux x86_64.

Ok to commit ?

François

Comments

Jonathan Wakely Oct. 18, 2018, 8:34 p.m. | #1
On 18/10/18 22:12 +0200, François Dumont wrote:
>Current build of libstdc++ with 

>--enable-symvers=gnu-versioned-namespace fails (at least under Linux) 

>because of:

>

>In file included from /home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/memory_resource:39,

>                 from 

>../../../../../git/libstdc++-v3/src/c++17/memory_resource.cc:25:

>/home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/cstddef:71:59: 

>error: la référence à « byte » est ambiguë

>   71 |   template<> struct __byte_operand<bool> { using __type = byte; };

>      | ^~~~

>In file included from /home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/stl_algobase.h:61,

>                 from /home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/memory:62,

>                 from /home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/memory_resource:37,

>                 from 

>../../../../../git/libstdc++-v3/src/c++17/memory_resource.cc:25:

>/home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/cpp_type_traits.h:395:30: 

>note: les candidats sont : « enum class std::__8::byte »

>  395 |   enum class byte : unsigned char;

>      |                              ^~~~

>In file included from /home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/memory_resource:39,

>                 from 

>../../../../../git/libstdc++-v3/src/c++17/memory_resource.cc:25:

>/home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/cstddef:68:14: 

>note:                      « enum class std::byte »

>   68 |   enum class byte : unsigned char {};

>      |              ^~~~

>

>I think the issue if that std::byte declaration in cpp_type_traits.h 

>has been done in versioned namespace, so the attached patch.


I think the definitions in <cstddef> should use the versioned
namespace macros. Then <bits/cpp_type_traits.h> would be correct.


>    * include/bits/cpp_type_traits.h (std::byte): Move outside versioned

>    namespace.

>

>Tested under Linux x86_64.

>

>Ok to commit ?

>

>François

>


>diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h

>index 960d469f412..fa7fc7564c2 100644

>--- a/libstdc++-v3/include/bits/cpp_type_traits.h

>+++ b/libstdc++-v3/include/bits/cpp_type_traits.h

>@@ -68,6 +68,10 @@ extern "C++" {

> 

> namespace std _GLIBCXX_VISIBILITY(default)

> {

>+#if __cplusplus >= 201703L

>+  enum class byte : unsigned char;

>+#endif

>+

> _GLIBCXX_BEGIN_NAMESPACE_VERSION

> 

>   struct __true_type { };

>@@ -392,8 +396,6 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3)

>     };

> 

> #if __cplusplus >= 201703L

>-  enum class byte : unsigned char;

>-

>   template<>

>     struct __is_byte<byte>

>     {

>
François Dumont Oct. 23, 2018, 5:07 a.m. | #2
On 10/18/2018 10:34 PM, Jonathan Wakely wrote:
> On 18/10/18 22:12 +0200, François Dumont wrote:

>> Current build of libstdc++ with 

>> --enable-symvers=gnu-versioned-namespace fails (at least under Linux) 

>> because of:

>>

>> In file included from 

>> /home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/memory_resource:39,

>>                  from 

>> ../../../../../git/libstdc++-v3/src/c++17/memory_resource.cc:25:

>> /home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/cstddef:71:59: 

>> error: la référence à « byte » est ambiguë

>>    71 |   template<> struct __byte_operand<bool> { using __type = 

>> byte; };

>>       | ^~~~

>> In file included from 

>> /home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/stl_algobase.h:61,

>>                  from 

>> /home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/memory:62,

>>                  from 

>> /home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/memory_resource:37,

>>                  from 

>> ../../../../../git/libstdc++-v3/src/c++17/memory_resource.cc:25:

>> /home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/cpp_type_traits.h:395:30: 

>> note: les candidats sont : « enum class std::__8::byte »

>>   395 |   enum class byte : unsigned char;

>>       |                              ^~~~

>> In file included from 

>> /home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/memory_resource:39,

>>                  from 

>> ../../../../../git/libstdc++-v3/src/c++17/memory_resource.cc:25:

>> /home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/cstddef:68:14: 

>> note:                      « enum class std::byte »

>>    68 |   enum class byte : unsigned char {};

>>       |              ^~~~

>>

>> I think the issue if that std::byte declaration in cpp_type_traits.h 

>> has been done in versioned namespace, so the attached patch.

>

> I think the definitions in <cstddef> should use the versioned

> namespace macros. Then <bits/cpp_type_traits.h> would be correct.

I thought cstddef was some kind of generated file.

I eventually put all its content in versioned namespace.

     * include/c_global/cstddef: Add versioned namespace.

Build successful with the patch, still tests to run. Ok if successful ?

François
diff --git a/libstdc++-v3/include/c_global/cstddef b/libstdc++-v3/include/c_global/cstddef
index 0ca3b82338a..b6d4a13c0b1 100644
--- a/libstdc++-v3/include/c_global/cstddef
+++ b/libstdc++-v3/include/c_global/cstddef
@@ -62,6 +62,7 @@ namespace std
 #if __cplusplus >= 201703L
 namespace std
 {
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
 #define __cpp_lib_byte 201603
 
   /// std::byte
@@ -187,6 +188,7 @@ namespace std
     to_integer(__byte_op_t<_IntegerType> __b) noexcept
     { return _IntegerType(__b); }
 
+_GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
 #endif // C++17
 } // extern "C++"
Jonathan Wakely Oct. 23, 2018, 9:37 a.m. | #3
On 23/10/18 07:07 +0200, François Dumont wrote:
>On 10/18/2018 10:34 PM, Jonathan Wakely wrote:

>>On 18/10/18 22:12 +0200, François Dumont wrote:

>>>Current build of libstdc++ with 

>>>--enable-symvers=gnu-versioned-namespace fails (at least under 

>>>Linux) because of:

>>>

>>>In file included from /home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/memory_resource:39,

>>>                 from 

>>>../../../../../git/libstdc++-v3/src/c++17/memory_resource.cc:25:

>>>/home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/cstddef:71:59: 

>>>error: la référence à « byte » est ambiguë

>>>   71 |   template<> struct __byte_operand<bool> { using __type = 

>>>byte; };

>>>      | ^~~~

>>>In file included from /home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/stl_algobase.h:61,

>>>                 from /home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/memory:62,

>>>                 from /home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/memory_resource:37,

>>>                 from 

>>>../../../../../git/libstdc++-v3/src/c++17/memory_resource.cc:25:

>>>/home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/cpp_type_traits.h:395:30: 

>>>note: les candidats sont : « enum class std::__8::byte »

>>>  395 |   enum class byte : unsigned char;

>>>      |                              ^~~~

>>>In file included from /home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/memory_resource:39,

>>>                 from 

>>>../../../../../git/libstdc++-v3/src/c++17/memory_resource.cc:25:

>>>/home/fdt/dev/gcc/build_versioned_ns/x86_64-pc-linux-gnu/libstdc++-v3/include/cstddef:68:14: 

>>>note:                      « enum class std::byte »

>>>   68 |   enum class byte : unsigned char {};

>>>      |              ^~~~

>>>

>>>I think the issue if that std::byte declaration in 

>>>cpp_type_traits.h has been done in versioned namespace, so the 

>>>attached patch.

>>

>>I think the definitions in <cstddef> should use the versioned

>>namespace macros. Then <bits/cpp_type_traits.h> would be correct.

>I thought cstddef was some kind of generated file.

>

>I eventually put all its content in versioned namespace.

>

>    * include/c_global/cstddef: Add versioned namespace.

>

>Build successful with the patch, still tests to run. Ok if successful ?


Yes, OK thanks.

Patch

diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h
index 960d469f412..fa7fc7564c2 100644
--- a/libstdc++-v3/include/bits/cpp_type_traits.h
+++ b/libstdc++-v3/include/bits/cpp_type_traits.h
@@ -68,6 +68,10 @@  extern "C++" {
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
+#if __cplusplus >= 201703L
+  enum class byte : unsigned char;
+#endif
+
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   struct __true_type { };
@@ -392,8 +396,6 @@  __INT_N(__GLIBCXX_TYPE_INT_N_3)
     };
 
 #if __cplusplus >= 201703L
-  enum class byte : unsigned char;
-
   template<>
     struct __is_byte<byte>
     {