In fact, void is the default for std::less, so the common idiom is to just use std::less. So std::less was specified to be a specialization where all its members are templates - so they use whatever types they are called with, rather than baking in the KeyType - hence transparent. It’s that KeyType that’s causing our issue. The associative containers take a template argument for a comparator, which defaults to std::less. So C++14 introduced transparent comparators. That all seems a shame, given that we’re only using the string to compare against each element - and comparisons already work across these string types. If that is an issue for you it’s hard to spot that just by looking at it. It’s a const-ref to a string, but it will still have to create a temporary string and copy the characters in. We are passing a string literal, but find takes its argument by the key type of the container - in this case std::string. And when you run that, it will work as you might expect and produce the results you intended. So let’s take a look at something less obvious. And note the link to a more in-depth rule description.īut the benefits of using const, here, are well known, and it’s often easy to spot them by eye. clang-tidy has the readability-non-const-parameter check, which has the same goal, but, at time of writing, only works for pointers to numeric types - so for:Ĭlang-tidy is silent, but SonarLint reports: Some of what SonarLint calls Rules are expanded forms of Inspections already found in CLion in a more limited form (often coming from clang-tidy).Ī great example of this is S995, which detects if parameters, taken by pointer or reference, could be made const. Rules that build on Checks and InspectionsĬLion has a great set of what it calls Inspections already built in - many of which it integrates directly from clang-tidy Checks. Through that lens, we want to show how you can leverage them to elevate your CLion’s inbuilt static analysis capabilities. In this post, we want to demonstrate the powerful capabilities of the C++ analyzer with SonarLint (a free, in-IDE static analysis plugin) and highlight some unique and interesting rules that you might find useful. Since then, the team has continued to bring even greater value to the C and C++ users, continuing our mission to empower the community to deliver code that meets the highest quality and security standards. Earlier this year we launched the support for C and C++ in SonarLint for CLion to address quality and security issues for your C/C++ projects.
0 Comments
Leave a Reply. |