[PATCH] D15228: [PATCH] New diagnostic for non-idiomatic copy or move operations

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 4 06:13:37 PST 2015


aaron.ballman created this revision.
aaron.ballman added reviewers: rsmith, dblaikie.
aaron.ballman added a subscriber: cfe-commits.

All copy operations were created equal (as far as the core language is concerned), but some copy operations are more equal than others (as far as the library is concerned). The same is true of move operations. This patch diagnoses copy and move operations (constructors and assignment operators) that are non-idiomatic so that users are not surprised when their copyable type cannot be placed in a standard library container or used with a standard library algorithm.

Idiomatic copy and move operations are (where T is the class type for the object):
Copy Constructor: takes a const T&
Move constructor: takes a T&&
Copy Assignment: takes a const T&, returns a T&, and has no ref-qualifiers
Move Assignment: takes a T&&, returns a T&, and has no ref-qualifiers

One thing this patch does not have, but I would like to add, are fix-it hints to correct the types involved. However, I cannot find a way to get the full source range for the type, including qualifiers. For a parameter of type 'const volatile T&', the TypeLoc appears to only track the location of T&, but not the qualifiers. Assistance in understanding how to do this would be appreciated.


http://reviews.llvm.org/D15228

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/Sema/SemaDeclCXX.cpp
  test/SemaCXX/warn-non-idiomatic-copy-move.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15228.41869.patch
Type: text/x-patch
Size: 13661 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151204/7d095185/attachment-0001.bin>


More information about the cfe-commits mailing list