[PATCH] New warning -Wpessimizing-move to catch when removing calls to std::move in return statements will result in NRVO

Richard Trieu rtrieu at google.com
Fri Feb 13 15:55:58 PST 2015


This warning will catch code such as:

class X {};
X foo() {
  X x;
  return std::move(x);
}

where NRVO could have been applied if a call to std::move was not used.  This will emit one warning per function, with one note per return statement that needs updated.

class.cc:15:3: warning: return value optimization for function 'foo' prevented
      by call to std::move on return statement [-Wpessimizing-move]
X foo() {
  ^
class.cc:17:7: note: remove call to std::move here to allow return value
      optimization
      return std::move(x);
      ^      ~~~~~~~~~~~~
             x
1 warning generated.

http://reviews.llvm.org/D7633

Files:
  include/clang/AST/Stmt.h
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/ScopeInfo.h
  include/clang/Sema/Sema.h
  lib/Sema/ScopeInfo.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaStmt.cpp

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7633.19944.patch
Type: text/x-patch
Size: 12057 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150213/a0b775de/attachment.bin>


More information about the cfe-commits mailing list