-
Notifications
You must be signed in to change notification settings - Fork 28
Description
Since constness in C++ is a shallow property (i.e. does not propagate downwards through nested datastructures), even with the new const visitor interface some class members of AST classes can still be changed. For example, for AST::BinaryOperator' the following operation is now prevented by the const` visitor:
void visit(const std::shared_ptr& expr) override {
expr->getLeft() = expr->getRight();
The following unfortunately still compiles:
void visit(const std::shared_ptr& expr) override {
*(expr->getLeft()) = *(expr->getRight());
One possible way to prevent this behavior is using std::experimental::propagate_const. We should evaluate if this is worth it. It has to work with gcc 8 since that is our target compiler.
Another much simpler option might be for the const getter of these classes to return a const shared_ptr<const T>
.