File | Mode | Size |
---|---|---|
test-files/ | 040000 | |
CMakeLists.txt | 100644 | 214B |
LICENSE | 100644 | 18KiB |
README.md | 100644 | 1,217B |
for-postfix.cpp | 100644 | 3,774B |
Clang-based standalone tool that detects for-loops with postfix operators.
Input:
#include <cstdlib>
#include <vector>
inline void
doNothing()
{
// do nothing on purpose
}
int
main(void)
{
std::vector<int> v;
typedef std::vector<int> intVector;
for (intVector::const_iterator cit = v.begin(); cit != v.end(); cit++) {
doNothing();
}
for (intVector::const_iterator cit = v.begin(); cit != v.end(); ++cit) {
doNothing();
}
for (intVector::const_iterator cit = v.begin(); cit != v.end(); cit--) {
doNothing();
}
for (intVector::const_iterator cit = v.begin(); cit != v.end(); --cit) {
doNothing();
}
return EXIT_SUCCESS;
}
Run command:
bin/for-postfix vector-all.cpp --
Output (paths are truncated):
.../vector-all.cpp:17:dangerous use of postfix operator
.../vector-all.cpp:25:dangerous use of postfix operator
llvm/tools/clang/tools/extra
.add_subdirectory(for-postfix)
to CMakeLists.txt
in the same
directory.ninja for-postfix
inside your LLVM's build/
directory.