xtypes icon indicating copy to clipboard operation
xtypes copied to clipboard

xtypes not compiling due to `basic_string(nullptr_t) = delete;` in C++23

Open russkel opened this issue 7 months ago • 0 comments

Hello,

I am using xtypes in a library where I have used a certain amount of C++23 features. When compiling I ran into a header issue (PR incoming) and this trickier issue:

In file included from /home/work/ws/install/xtypes/include/xtypes/StringType.hpp:22,
                 from /home/work/ws/install/xtypes/include/xtypes/xtypes.hpp:24,
                 from /home/work/ws/install/nmea0183reader/include/nmea0183reader/definition_plugin.hpp:5,
                 from /home/work/ws/src/nmea0183_lib/include/nmea0183_lib/converters.hpp:6,
                 from /home/work/ws/src/nmea0183_lib/src/xtypes_structs.cpp:4:
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp: In instantiation of ‘void eprosima::xtypes::PrimitiveType<T>::construct_instance(uint8_t*) const [with T = std::__cxx11::basic_string<char16_t>; uint8_t = unsigned char]’:
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:117:18:   required from here
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:120:43: error: use of deleted function ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::nullptr_t) [with _CharT = char16_t; _Traits = std::char_traits<char16_t>; _Alloc = std::allocator<char16_t>; std::nullptr_t = std::nullptr_t]’
  120 |         *reinterpret_cast<T*>(instance) = T(0);
      |                                           ^~~~
In file included from /usr/include/c++/12/string:53,
                 from /usr/include/c++/12/bits/locale_classes.h:40,
                 from /usr/include/c++/12/bits/ios_base.h:41,
                 from /usr/include/c++/12/ios:42,
                 from /usr/include/c++/12/ostream:38,
                 from /usr/include/c++/12/iostream:39,
                 from /home/work/ws/install/xtypes/include/xtypes/Assert.hpp:21,
                 from /home/work/ws/install/xtypes/include/xtypes/DynamicType.hpp:21,
                 from /home/work/ws/install/xtypes/include/xtypes/CollectionType.hpp:21,
                 from /home/work/ws/install/xtypes/include/xtypes/ArrayType.hpp:21,
                 from /home/work/ws/install/xtypes/include/xtypes/xtypes.hpp:23:
/usr/include/c++/12/bits/basic_string.h:742:7: note: declared here
  742 |       basic_string(nullptr_t) = delete;
      |       ^~~~~~~~~~~~
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp: In instantiation of ‘void eprosima::xtypes::PrimitiveType<T>::construct_instance(uint8_t*) const [with T = std::__cxx11::basic_string<wchar_t>; uint8_t = unsigned char]’:
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:117:18:   required from here
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:120:43: error: use of deleted function ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::nullptr_t) [with _CharT = wchar_t; _Traits = std::char_traits<wchar_t>; _Alloc = std::allocator<wchar_t>; std::nullptr_t = std::nullptr_t]’
  120 |         *reinterpret_cast<T*>(instance) = T(0);
      |                                           ^~~~
/usr/include/c++/12/bits/basic_string.h:742:7: note: declared here
  742 |       basic_string(nullptr_t) = delete;
      |       ^~~~~~~~~~~~
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp: In instantiation of ‘void eprosima::xtypes::PrimitiveType<T>::construct_instance(uint8_t*) const [with T = std::__cxx11::basic_string<char>; uint8_t = unsigned char]’:
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:117:18:   required from here
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:120:43: error: use of deleted function ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::nullptr_t) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::nullptr_t = std::nullptr_t]’
  120 |         *reinterpret_cast<T*>(instance) = T(0);
      |                                           ^~~~
/usr/include/c++/12/bits/basic_string.h:742:7: note: declared here
  742 |       basic_string(nullptr_t) = delete;
      |       ^~~~~~~~~~~~
In file included from /home/work/ws/install/xtypes/include/xtypes/StringType.hpp:22,
                 from /home/work/ws/install/xtypes/include/xtypes/xtypes.hpp:24,
                 from /home/work/ws/install/nmea0183reader/include/nmea0183reader/definition_plugin.hpp:5,
                 from /home/work/ws/src/nmea0183_lib/include/nmea0183_lib/converters.hpp:6,
                 from /home/work/ws/src/nmea0183_lib/src/converters_ref.cpp:5:
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp: In instantiation of ‘void eprosima::xtypes::PrimitiveType<T>::construct_instance(uint8_t*) const [with T = std::__cxx11::basic_string<char16_t>; uint8_t = unsigned char]’:
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:117:18:   required from here
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:120:43: error: use of deleted function ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::nullptr_t) [with _CharT = char16_t; _Traits = std::char_traits<char16_t>; _Alloc = std::allocator<char16_t>; std::nullptr_t = std::nullptr_t]’
  120 |         *reinterpret_cast<T*>(instance) = T(0);
      |                                           ^~~~
In file included from /usr/include/c++/12/string:53,
                 from /usr/include/c++/12/bits/locale_classes.h:40,
                 from /usr/include/c++/12/bits/ios_base.h:41,
                 from /usr/include/c++/12/ios:42,
                 from /usr/include/c++/12/ostream:38,
                 from /usr/include/c++/12/iostream:39,
                 from /home/work/ws/install/xtypes/include/xtypes/Assert.hpp:21,
                 from /home/work/ws/install/xtypes/include/xtypes/DynamicType.hpp:21,
                 from /home/work/ws/install/xtypes/include/xtypes/CollectionType.hpp:21,
                 from /home/work/ws/install/xtypes/include/xtypes/ArrayType.hpp:21,
                 from /home/work/ws/install/xtypes/include/xtypes/xtypes.hpp:23:
/usr/include/c++/12/bits/basic_string.h:742:7: note: declared here
  742 |       basic_string(nullptr_t) = delete;
      |       ^~~~~~~~~~~~
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp: In instantiation of ‘void eprosima::xtypes::PrimitiveType<T>::construct_instance(uint8_t*) const [with T = std::__cxx11::basic_string<wchar_t>; uint8_t = unsigned char]’:
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:117:18:   required from here
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:120:43: error: use of deleted function ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::nullptr_t) [with _CharT = wchar_t; _Traits = std::char_traits<wchar_t>; _Alloc = std::allocator<wchar_t>; std::nullptr_t = std::nullptr_t]’
  120 |         *reinterpret_cast<T*>(instance) = T(0);
      |                                           ^~~~
/usr/include/c++/12/bits/basic_string.h:742:7: note: declared here
  742 |       basic_string(nullptr_t) = delete;
      |       ^~~~~~~~~~~~
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp: In instantiation of ‘void eprosima::xtypes::PrimitiveType<T>::construct_instance(uint8_t*) const [with T = std::__cxx11::basic_string<char>; uint8_t = unsigned char]’:
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:117:18:   required from here
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:120:43: error: use of deleted function ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::nullptr_t) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::nullptr_t = std::nullptr_t]’
  120 |         *reinterpret_cast<T*>(instance) = T(0);
      |                                           ^~~~
/usr/include/c++/12/bits/basic_string.h:742:7: note: declared here
  742 |       basic_string(nullptr_t) = delete;
      |       ^~~~~~~~~~~~

I am hoping this isn't that difficult to fix, do I have to modify these particular types to construct empty strings instead? It looks like it wasn't valid to begin with, if I simply try to construct a string with nullptr in C++20:

Program returned: 139
terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string: construction from null is not valid
Program terminated with signal: SIGSEGV

I am not sure where T is being set to a basic_string because that shouldn't be a valid type for a PrimitiveType? The compiler was being no help in finding it.

russkel avatar Dec 20 '23 05:12 russkel