glfwpp icon indicating copy to clipboard operation
glfwpp copied to clipboard

Build failure on GCC 12.2.0: Missing include for `std::exchange`

Open automaticp opened this issue 2 years ago • 2 comments

OS: Ubuntu 22.10 Compiler: GCC 12.2.0

Relevang build log:

...
[ 72%] Building CXX object examples/CMakeFiles/glfwpp_example_basic.dir/basic.cpp.o
In file included from /home/automatic/projects/glfwpp/include/glfwpp/joystick.h:4,
                 from /home/automatic/projects/glfwpp/include/glfwpp/glfwpp.h:10,
                 from /home/automatic/projects/glfwpp/examples/basic.cpp:3:
/home/automatic/projects/glfwpp/include/glfwpp/helper.h: In constructor ‘constexpr glfw::detail::OwningPtr<T>::OwningPtr(glfw::detail::OwningPtr<T>&&)’:
/home/automatic/projects/glfwpp/include/glfwpp/helper.h:49:27: error: ‘exchange’ is not a member of ‘std’
   49 |                 _ptr{std::exchange(other._ptr, nullptr)}
      |                           ^~~~~~~~
/home/automatic/projects/glfwpp/include/glfwpp/helper.h: In member function ‘constexpr glfw::detail::OwningPtr<T>& glfw::detail::OwningPtr<T>::operator=(glfw::detail::OwningPtr<T>&&)’:
/home/automatic/projects/glfwpp/include/glfwpp/helper.h:55:29: error: ‘exchange’ is not a member of ‘std’
   55 |                 _ptr = std::exchange(other._ptr, nullptr);
      |                             ^~~~~~~~
/home/automatic/projects/glfwpp/include/glfwpp/helper.h: In instantiation of ‘constexpr glfw::detail::OwningPtr<T>::OwningPtr(glfw::detail::OwningPtr<T>&&) [with T = GLFWwindow]’:
/home/automatic/projects/glfwpp/include/glfwpp/window.h:446:63:   required from here
/home/automatic/projects/glfwpp/include/glfwpp/helper.h:49:17: error: cannot convert ‘<brace-enclosed initializer list>’ to ‘GLFWwindow*’ in initialization
   49 |                 _ptr{std::exchange(other._ptr, nullptr)}
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gmake[2]: *** [examples/CMakeFiles/glfwpp_example_basic.dir/build.make:76: examples/CMakeFiles/glfwpp_example_basic.dir/basic.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:374: examples/CMakeFiles/glfwpp_example_basic.dir/all] Error 2
gmake: *** [Makefile:136: all] Error 2

Was building previously without issues on Ubuntu 22.04 and GCC 11.2.0, seems like libstdc++ devs have cleaned up their headers and <type_traits> no longer transparently includes <utility>. Which shouldn't have been something you'd rely on either way.

automaticp avatar Dec 29 '22 15:12 automaticp

Also this is something I've noticed throughout all the headers: they rely too much on transparent includes like this. For example, window.h uses std::move, std::vector and std::tuple but does not include the relevant headers directly, rather it relies on the includes from helper.h and monitor.h.

This kind of approach is fragile and can lead to issues like the one above. Should a separate issue be opened to adopt a more 'include-what-you-use' approach, perhaps?

automaticp avatar Dec 29 '22 15:12 automaticp

Same problem here! It was fixed by add #include utility too.

danielbrupaiva avatar Mar 21 '24 23:03 danielbrupaiva