Skip to content

Commit 1333147

Browse files
committed
Make OpOperand constructor private (NFC)
This is intended to avoid programming mistake where a temporary OpOperand is created, for example: for (OpOperand user : result.getUsers()) { It can be confusing for the user, in particular since in MLIR most classes are intended to be copied around by value while they have reference semantics. Differential Revision: https://reviews.llvm.org/D81815
1 parent 7c93a19 commit 1333147

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

mlir/include/mlir/IR/UseDefLists.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,6 @@ class OpaqueValue {
249249
/// contain a reference to a specific `Value`.
250250
class OpOperand : public IROperand<OpOperand, detail::OpaqueValue> {
251251
public:
252-
using IROperand<OpOperand, detail::OpaqueValue>::IROperand;
253-
254252
/// Provide the use list that is attached to the given value.
255253
static IRObjectWithUseList<OpOperand> *getUseList(Value value);
256254

@@ -262,6 +260,12 @@ class OpOperand : public IROperand<OpOperand, detail::OpaqueValue> {
262260

263261
/// Return which operand this is in the operand list of the User.
264262
unsigned getOperandNumber();
263+
264+
private:
265+
/// Keep the constructor private and accessible to the OperandStorage class
266+
/// only to avoid hard-to-debug typo/programming mistakes.
267+
friend class OperandStorage;
268+
using IROperand<OpOperand, detail::OpaqueValue>::IROperand;
265269
};
266270

267271
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)