[PATCH] D45601: Warn on bool* to bool conversion
Arthur O'Dwyer via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 12 17:19:00 PDT 2018
Quuxplusone added inline comments.
================
Comment at: test/CXX/expr/expr.unary/expr.unary.op/p6.cpp:18
// -- pointer,
bool b6 = !&b4; // expected-warning{{address of 'b4' will always evaluate to 'true'}}
+// expected-warning at -1 {{comparing 'bool *' as a boolean}}
----------------
This is not "comparing" anything, so the warning seems inappropriate here. Maybe "implicitly converting 'bool *' to 'bool' in operand of '!'` would be more appropriate?
Please add test cases for `operator!`, `operator&&`, `operator||`, and `operator?`.
================
Comment at: test/Sema/static-init.c:10
intptr_t s = (intptr_t) &s;
-_Bool t = &t;
+_Bool t = &t; // expected-warning {{comparing '_Bool *' as a boolean}}
----------------
Again, not "comparing" anything.
Incidentally, do you know why this line fails to produce an "address of 't' will always evaluate to 'true'" warning?
================
Comment at: test/SemaCXX/warn-bool-ptr-to-bool.cpp:5
+ if (b)
+ // expected-warning at -1 {{comparing 'bool *' as a boolean}}
+ return 10;
----------------
Please add a test case
```
template<class T>
T foo(T *ptr) {
return ptr ? *ptr : T{};
}
bool bar(bool *ptr) { return foo(ptr); }
```
and make sure the warning does not trigger in this case. (It would be OK to trigger a clang-tidy check in this case, but IMHO not a `-W -Wall -Wextra` warning.)
https://reviews.llvm.org/D45601
More information about the cfe-commits
mailing list