[PATCH] D11784: [PATCH] clang-tidy check for incorrect move constructor initializers
Aaron Ballman
aaron.ballman at gmail.com
Wed Aug 5 14:57:56 PDT 2015
aaron.ballman created this revision.
aaron.ballman added reviewers: klimek, alexfh, djasper.
aaron.ballman added a subscriber: cfe-commits.
This patch adds a new clang-tidy to identify situations where a user is accidentally calling a copy constructor instead of a move constructor as part of a constructor initializer list. The code is likely to silently "work", but with surprising results. Consider:
struct B {
B() {}
B(const B&) {}
B(B &&) {}
};
struct D : B {
D() : B() {}
D(const D &RHS) : B(RHS) {} // Correct
D(D &&RHS) : B(RHS) {} // Oops, calls the copy constructor
};
One thing I am not certain of in this patch is how to test it. I have some rudimentary tests, but am unable to test the "note:" diagnostics from FileCheck (attempting to add any cause the "warning:" diagnostics to not be found). I suspect this is why clang-tidy.sh exists, but unfortunately, that means the tests will not be run on Windows (which is the platform I am developing on). Suggestions on how to improve the tests are welcome, but for now, I'm not testing the note diagnostics.
Another problem I'm not certain how to solve is how to phrase the note diagnostics with the constructors are implicitly-defined instead of written. Currently, the notes attach to the record declaration. Would it make sense to have extra text in that case which tells the user the constructors are implicitly defined? Or is there a better way to surface the notes?
Thanks!
~Aaron
http://reviews.llvm.org/D11784
Files:
clang-tidy/misc/CMakeLists.txt
clang-tidy/misc/MiscTidyModule.cpp
clang-tidy/misc/MoveConstructorBaseCheck.cpp
clang-tidy/misc/MoveConstructorBaseCheck.h
test/clang-tidy/misc-move-constructor-base.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11784.31398.patch
Type: text/x-patch
Size: 7419 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150805/eb1e279c/attachment-0001.bin>
More information about the cfe-commits
mailing list