Skip to content

Moving a temporary object in sinkhandle.hpp warning #564

Description

@thansen0

Describe the bug

I'm getting this warning in sinkhandle.hpp

my_file_path.cpp:69:25:   required from here
file/path/extern/g3log/src/g3log/sinkhandle.hpp:47:50: error: moving a temporary object prevents copy elision [-Werror=pessimizing-move]
   47 |             return std::move(promise.get_future());
      |

It appears to me that the code is attempting to move a temporary std::promise, which is incorrect. To my understanding we should just return the promise without the move.

To Reproduce

  • What system, compiler etc was used to run this?
    I am using g++ with C++20 on ubuntu 24.04. I added g3log as a subdirectory and am running off the most recent version of master.
  • Is something done differently on your setup than what the documentation specifies?
    No, I believe this is the intended use case for call()
  • Have you provided a code snippet that can be tested?

My current setup is I have g3log in my extern/ folder, and the project is added through cmake add_subdirectory(${CMAKE_SOURCE_DIR}/extern/g3log). I have a custom sink, and when I try to call a function in my custom sink to update runtime variables, i.e.

sinkHandle->call(&MyCustomSink::setMinLevel, log_level_min);

I get the warning about moving a temporary object. I can add a more detailed code snipped later today if needed.

Additional context
Add any other context about the problem here.

The fix seems to be removing the std::move() from the return in SinkHandle::call(). This resolves the warning and logically makes sense for the code.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions