Open LegalizeAdulthood opened 8 years ago
Oops, ignore my last comment, it was intended for another bug.
A similar check could be created for std::string::operator== vs std::string::compare
This isn't the same thing, because we are checking for more things than just constructing an object.
Clang-tidy already has readability-redundant-string-init check which work for STL strings. Will be good idea to expand it instead iof introducing new one.
This is a general issue with std::string
. There are cases where using a per-constructed object is faster and others where it isn't. See https://github.com/danmar/cppcheck/pull/4034 where I apply a few such changes to make the Cppcheck code base consistent.
There's also #58002, #60165, https://github.com/danmar/cppcheck/pull/4337 (and most likely more) where I try (often awkwardly) to dig into sub-optimal/inconsistent code being for pattern which appear to be the same.
As I have haven't had much experience with c++17 and do not work on a code base which actively uses it I did not look into how std::string_view
would play into this.
Extended Description
wxWidgets has a preconstructed empty string object wxEmptyString of type wxString.
This should be preferred over wxT("") as this constructs an anonymously named temporary of type wxString wherever wxEmptyString could be used instead.
Particularly for default values of functions taking references to const wxString, this can save creating and destroying anonymous temporaries for every function call.
There are probably other wxWidgets idioms that make sense for clang-tidy.
This check should probably go in a wxWidgets module.