Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluate options for deep constness of AST classes #1103

Open
muellch opened this issue Feb 6, 2021 · 0 comments
Open

Evaluate options for deep constness of AST classes #1103

muellch opened this issue Feb 6, 2021 · 0 comments
Labels

Comments

@muellch
Copy link
Contributor

muellch commented Feb 6, 2021

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

@muellch muellch added backend dawn related refactoring labels Feb 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant