Skip to content

Evaluate options for deep constness of AST classes #1103

@muellch

Description

@muellch

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>.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions