[SERVER-18668] -Wpessimizing-move warnings with clang-3.7 Created: 26/May/15  Updated: 19/Sep/15  Resolved: 25/Aug/15

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: 3.1.3
Fix Version/s: 3.1.8

Type: Bug Priority: Minor - P4
Reporter: Kamran K. Assignee: Adam Midvidy
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Platform 8 08/28/15
Participants:

 Description   

clang-3.7 introduces a -Wpessimizing-move warning that "warns when a call to std::move would prevent copy elision if the argument was not wrapped in a call."

These are the current warnings with non-enterprise master (6ff771d5e):

src/mongo/client/dbclient.cpp:336:16: error: moving a temporary object prevents copy elision [-Werror,-Wpessimizing-move]
        info = std::move(commandReply->getCommandReply().getOwned());
               ^
src/mongo/client/dbclient.cpp:336:16: note: remove std::move call here
        info = std::move(commandReply->getCommandReply().getOwned());
               ^~~~~~~~~~                                          ~

src/mongo/rpc/legacy_reply_builder.cpp:97:16: error: moving a local object in a return statement prevents copy elision [-Werror,-Wpessimizing-move]
        return std::move(message);
               ^
src/mongo/rpc/legacy_reply_builder.cpp:97:16: note: remove std::move call here
        return std::move(message);
               ^~~~~~~~~~       ~

src/mongo/rpc/metadata.cpp:54:57: error: moving a temporary object prevents copy elision [-Werror,-Wpessimizing-move]
        return std::make_tuple(std::move(legacyCmdObj), std::move(metadataBob.obj()));
                                                        ^
src/mongo/rpc/metadata.cpp:54:57: note: remove std::move call here
        return std::make_tuple(std::move(legacyCmdObj), std::move(metadataBob.obj()));

src/third_party/s2/base/logging.cc:33:51: error: moving a temporary object prevents copy elision [-Werror,-Wpessimizing-move]
LogMessageInfo::LogMessageInfo() : LogMessageBase(std::move(mongo::log())) { }
                                                  ^
src/third_party/s2/base/logging.cc:33:51: note: remove std::move call here
LogMessageInfo::LogMessageInfo() : LogMessageBase(std::move(mongo::log())) { }

src/mongo/util/decoration_registry.h:66:21: error: moving a temporary object prevents copy elision [-Werror,-Wpessimizing-move]
                    std::move(declareDecoration(sizeof(T),
                    ^
src/mongo/util/decorable.h:105:49: note: in instantiation of function template specialization 'mongo::DecorationRegistry::declareDecoration<std::unique_ptr<mongo::AuthenticationSession, std::default_delete<mongo::AuthenticationSession> > >' requested here
            return Decoration<T>(getRegistry()->declareDecoration<T>());
                                                ^
src/mongo/db/auth/auth_decorations.cpp:63:22: note: in instantiation of function template specialization 'mongo::Decorable<mongo::ClientBasic>::declareDecoration<std::unique_ptr<mongo::AuthenticationSession, std::default_delete<mongo::AuthenticationSession> > >'
      requested here
        ClientBasic::declareDecoration<std::unique_ptr<AuthenticationSession>>();
                     ^
src/mongo/util/decoration_registry.h:66:21: note: remove std::move call here
                    std::move(declareDecoration(sizeof(T),
                    ^~~~~~~~~~
src/mongo/util/decoration_registry.h:66:21: error: moving a temporary object prevents copy elision [-Werror,-Wpessimizing-move]
                    std::move(declareDecoration(sizeof(T),
                    ^
src/mongo/util/decorable.h:105:49: note: in instantiation of function template specialization 'mongo::DecorationRegistry::declareDecoration<std::unique_ptr<mongo::AuthorizationManager, std::default_delete<mongo::AuthorizationManager> > >' requested here
            return Decoration<T>(getRegistry()->declareDecoration<T>());
                                                ^
src/mongo/db/auth/auth_decorations.cpp:66:25: note: in instantiation of function template specialization 'mongo::Decorable<mongo::ServiceContext>::declareDecoration<std::unique_ptr<mongo::AuthorizationManager, std::default_delete<mongo::AuthorizationManager> > >'
      requested here
        ServiceContext::declareDecoration<std::unique_ptr<AuthorizationManager>>();
                        ^
src/mongo/util/decoration_registry.h:66:21: note: remove std::move call here
                    std::move(declareDecoration(sizeof(T),
                    ^~~~~~~~~~
src/mongo/util/decoration_registry.h:66:21: error: moving a temporary object prevents copy elision [-Werror,-Wpessimizing-move]
                    std::move(declareDecoration(sizeof(T),
                    ^
src/mongo/util/decorable.h:105:49: note: in instantiation of function template specialization 'mongo::DecorationRegistry::declareDecoration<std::unique_ptr<mongo::AuthorizationSession, std::default_delete<mongo::AuthorizationSession> > >' requested here
            return Decoration<T>(getRegistry()->declareDecoration<T>());
                                                ^
src/mongo/db/auth/auth_decorations.cpp:69:22: note: in instantiation of function template specialization 'mongo::Decorable<mongo::ClientBasic>::declareDecoration<std::unique_ptr<mongo::AuthorizationSession, std::default_delete<mongo::AuthorizationSession> > >' requested
      here
        ClientBasic::declareDecoration<std::unique_ptr<AuthorizationSession>>();
                     ^
src/mongo/util/decoration_registry.h:66:21: note: remove std::move call here
                    std::move(declareDecoration(sizeof(T),
                    ^~~~~~~~~~

src/mongo/s/balance.cpp:573:40: error: moving a temporary object prevents copy elision [-Werror,-Wpessimizing-move]
                        writeConcern = std::move(balancerConfig.getWriteConcern());
                                       ^
src/mongo/s/balance.cpp:573:40: note: remove std::move call here
                        writeConcern = std::move(balancerConfig.getWriteConcern());



 Comments   
Comment by Githook User [ 25/Aug/15 ]

Author:

{u'username': u'amidvidy', u'name': u'Adam Midvidy', u'email': u'amidvidy@gmail.com'}

Message: SERVER-18668 warn about pessimizing/redundant moves if compiler can do so
Branch: master
https://github.com/mongodb/mongo/commit/3e21b91dcc4d95a06e3f3a80142a686d92896cac

Comment by Githook User [ 25/Aug/15 ]

Author:

{u'username': u'amidvidy', u'name': u'Adam Midvidy', u'email': u'amidvidy@gmail.com'}

Message: SERVER-18668 remove some pessimizing and redundant moves
Branch: master
https://github.com/mongodb/mongo/commit/f480380df5107c2204ebbd250282dec18cc2a20d

Comment by Adam Midvidy [ 04/Jun/15 ]

One question - will this warning be triggered if the copy constructor/assignment op is deleted? When returning move-only classes it is sometimes necessary to explicitly move a return value.

Generated at Thu Feb 08 03:48:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.