SaferCPlusPlus
SaferCPlusPlus copied to clipboard
clang-tidy support for SaferCPlusPlus
Hi,
I saw a thread on clang mailing list discussing clang-tidy
support for SaferCPlusPlus.
Does that exist? Is there any way to verify the code does not contain unsafe constructs?
Not in clang-tidy, but there is a separate tool, scpptool, that does it. It's still a work in progress and not at all well tested yet, but it should have most of the essential functionality. The documentation is a work in progress as well, but feel free to ask any questions. In some cases it may not be initially obvious how to work around some of the restrictions. For example in this code
{
mse::mstd::vector<int> vec1{1, 2, 3};
for (auto& item : vec1) {
//vec1.clear();
item += 5;
}
}
the native reference item
would be flagged as "not verifiably safe". A "safe" alternative would probably be to use mse::for_each_ptr()
{
mse::mstd::vector<int> vec1{1, 2, 3};
mse::for_each_ptr(vec1.begin(), vec1.end(), [](auto item_ptr){ *item_ptr += 5; });
}