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

Add CastExp.toLvalue dip1000 error if implicit pointer conversion would fail #15597

Closed
wants to merge 3 commits into from

Conversation

ntrel
Copy link
Contributor

@ntrel ntrel commented Sep 10, 2023

From https://dlang.org/spec/expression.html#.define-lvalue

The following expressions, and no others, are called lvalue expressions or lvalues
...
cast(U) expressions applied to lvalues of type T when T* is implicitly convertible to U*;
cast() and cast(qualifier list) when applied to an lvalue.

The first rule was not enforced by dmd.
The second rule contradicts the point of the first rule. It should perhaps could be updated to work in the same way.

Fixes Issue 23530 - casting immutable away allowed in safe.

Edit: Changed to dip1000 error rather than obsolete warning.

From https://dlang.org/spec/expression.html#.define-lvalue

> The following expressions, and no others, are called lvalue expressions or lvalues
...
> cast(U) expressions applied to lvalues of type T when T* is implicitly convertible to U*;
> cast() and cast(qualifier list) when applied to an lvalue.

The first rule was not enforced by dmd.
The second rule contradicts the point of the first rule. It should be
updated to work in the same way.

Fixes Issue 23530 - casting immutable away allowed in safe.
@dlang-bot
Copy link
Contributor

dlang-bot commented Sep 10, 2023

Thanks for your pull request and interest in making D better, @ntrel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Auto-close Bugzilla Severity Description
23530 critical casting immutable away allowed in safe

⚠️⚠️⚠️ Warnings ⚠️⚠️⚠️

To target stable perform these two steps:

  1. Rebase your branch to upstream/stable:
git rebase --onto upstream/stable upstream/master
  1. Change the base branch of your PR to stable

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#15597"

@ntrel ntrel changed the title Add CastExp.toLvalue obsolete warning if implicit pointer conversion would fail Add CastExp.toLvalue dip1000 error if implicit pointer conversion would fail Sep 10, 2023
@ntrel ntrel changed the title Add CastExp.toLvalue dip1000 error if implicit pointer conversion would fail Add CastExp.toLvalue dip1000 error if implicit pointer conversion would fail Sep 10, 2023
@ntrel

This comment was marked as resolved.

@ntrel ntrel closed this Sep 11, 2023
@ntrel
Copy link
Contributor Author

ntrel commented Sep 12, 2023

I'm not sure where the cast expression comes from when calling _dupCtfe:

        foreach (ref e; a)
            res ~= e; // offending line

I tried to work around that by ignoring any casts in functions being interpreted at compile-time, but I'm clearly not detecting that correctly. Using SCOPE.ctfeBlock doesn't work either.

@ntrel
Copy link
Contributor Author

ntrel commented Mar 24, 2024

Closing in favour of #16315 (comment)

@ntrel ntrel closed this Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants