The current implementation of 'accept' has no const qualifier, and thus
it is impossible to apply visitor over const Instr objects.
Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
};
public:
- template<typename T> T accept(Visitor<T> *v)
+ template<typename T> T accept(Visitor<T> *v) const
{
if (auto ins = asUnitF())
{
throw std::runtime_error{"unreachable"};
}
- template<typename T> T accept(Visitor<T> &v) { return accept(&v); }
- template<typename T> T accept(Visitor<T> &&v) { return accept(&v); }
+ template<typename T> T accept(Visitor<T> &v) const { return accept(&v); }
+ template<typename T> T accept(Visitor<T> &&v) const { return accept(&v); }
};
} // namespace coco
coco::PtrLink<coco::Instr, coco::Block> link;
coco::UnitF ins{&link};
- ASSERT_TRUE(ins.accept(UnitFDetector{}));
+ coco::Instr *mutable_ptr = &ins;
+ const coco::Instr *immutable_ptr = &ins;
+
+ ASSERT_TRUE(mutable_ptr->accept(UnitFDetector{}));
+ ASSERT_TRUE(immutable_ptr->accept(UnitFDetector{}));
}