[PATCH] D15121: A new clang-tidy module to find calls to `std::swap`, and change them to use ADL
Marshall Clow via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 1 10:26:05 PST 2015
mclow.lists created this revision.
mclow.lists added reviewers: klimek, aaron.ballman, chandlerc.
mclow.lists added a subscriber: cfe-commits.
Motivation: LLVM has many overloads of `std::swap` for its own types. This is technically forbidden by the standard, but is pervasive in the LLVM code base. The correct fix for this is to put them in the same namespace as the thing that they are swapping - but do do this, we have to find (and fix) all the places where we call `std::swap` explicitly, and let ADL do the finding instead.
The basic transform is:
std::swap(x, y) --> { using std::swap; swap(x, y); }
This is the first cut at a tool to do this.
It's not quite right, in that it does this instead:
std::swap(x, y) --> { using std::swap; :swap(x, y); }
and I'm not quite sure why.
Also, the checking for builtin types and pointers needs to go into the matcher instead of the code.
Thanks to Manuel and Aaron for helping with this
http://reviews.llvm.org/D15121
Files:
clang-tidy/misc/CMakeLists.txt
clang-tidy/misc/MiscTidyModule.cpp
clang-tidy/misc/StdSwapCheck.cpp
clang-tidy/misc/StdSwapCheck.h
docs/clang-tidy/checks/list.rst
docs/clang-tidy/checks/misc-StdSwap.rst
test/clang-tidy/misc-StdSwap.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15121.41534.patch
Type: text/x-patch
Size: 10687 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151201/81f0232f/attachment.bin>
More information about the cfe-commits
mailing list