Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build failure on GCC 12.2.0: Missing include for std::exchange #264

Open
automaticp opened this issue Dec 29, 2022 · 2 comments · May be fixed by #265
Open

Build failure on GCC 12.2.0: Missing include for std::exchange #264

automaticp opened this issue Dec 29, 2022 · 2 comments · May be fixed by #265

Comments

@automaticp
Copy link

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
Copy link
Author

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?

@danielbrupaiva
Copy link

danielbrupaiva commented Mar 21, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants