Skip to content

Commit 43f6e04

Browse files
committed
Make mlir::OpState::operator bool explicit
This change makes the conversion of an mlir::OpState to bool `explicit`. Idiomatic boolean uses continue to work as before, but questionable implicit uses (e.g. accumulating over a range of OpStates to count "true" states) become ill-formed. This makes the class interface a lilttle less error-prone. I tested this change on our internal (fairly large) codebase, and only one fix was needed, which was ultimately an improvement of the affected code. Reviewed By: rriddle, mehdi_amini Differential Revision: https://reviews.llvm.org/D101989
1 parent 18cb17c commit 43f6e04

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mlir/include/mlir/IR/OpDefinition.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ void ensureRegionTerminator(
9393
/// they aren't customized.
9494
class OpState {
9595
public:
96-
/// Ops are pointer-like, so we allow implicit conversion to bool.
97-
operator bool() { return getOperation() != nullptr; }
96+
/// Ops are pointer-like, so we allow conversion to bool.
97+
explicit operator bool() { return getOperation() != nullptr; }
9898

9999
/// This implicitly converts to Operation*.
100100
operator Operation *() const { return state; }

0 commit comments

Comments
 (0)