[PATCH] D20857: [clang-tidy] Add modernize-explicit-operator-bool check.
Murray Cumming via cfe-commits
cfe-commits at lists.llvm.org
Sat Jun 4 01:27:02 PDT 2016
murrayc added a comment.
In http://reviews.llvm.org/D20857#449080, @alexfh wrote:
> Looks like a useful check to have. I'm not sure though, that it has anything to do with "modernize". I'd suggest adding a new "bugprone" module (should be added by http://reviews.llvm.org/D18821, hopefully soon) and moving the check there.
Fair enough. My logic is that this is a problem that can only be fixed properly in C++11 and that the best/correct/common way to do this has changed from C++98 to C++11. It's not just a nice use of new syntax (such as auto), it's also fixes bugs, but it's still use of new syntax.
================
Comment at: test/clang-tidy/modernize-explicit-operator-bool-void-pointer.cpp:6
@@ +5,3 @@
+ operator const void *() const {
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: implicit operator const void* declaration should probably be explicit operator bool [modernize-explicit-operator-bool]
+ return reinterpret_cast<void *>(something != 0);
----------------
alexfh wrote:
> From the first glance, this doesn't look like an easy mistake to make. Have you actually seen this pattern in real code?
Yes, in glibmm and gtkmm, which I maintain. This commit is from me though the idea wasn't:
https://git.gnome.org/browse/gtkmm/commit/gtk/src/treerowreference.hg?id=c182608593e2d4799f523580a0532fbc68d296b2
We later used a typedef to make that clearer:
https://git.gnome.org/browse/gtkmm/commit/gtk/src/treerowreference.hg?id=7dff74cca47827d6e34bc8f239674bf044ddedaa
There's lots of mention of this in StackOverflow, though not always so clearly. For instance: https://stackoverflow.com/questions/9134888/is-using-void-instead-of-bool-an-advisable-practice
http://reviews.llvm.org/D20857
More information about the cfe-commits
mailing list