Allow implicit conversion to a value expression to remove const. (#6253)

`const` doesn't mean much on the type of a value expression; it's valid
to remove it because we can't perform modifications to a const value
regardless.

We already allowed most of this, but only as part of adapter conversion
rather than in general, and we didn't previously allow it when the
source of the conversion was a reference expression.

---------

Co-authored-by: josh11b <15258583+josh11b@users.noreply.github.com>
This commit is contained in:
Richard Smith
2025-10-21 22:16:58 +00:00
committed by GitHub
co-authored by josh11b
parent 3ea16b8313
commit b3c25ecfa2
3 changed files with 120 additions and 20 deletions
+1 -9
View File
@@ -79,7 +79,7 @@ fn Value(v: Cpp.HasQualifiers) {
// CHECK:STDERR: | ^
v.ref_ref_this();
// CHECK:STDERR: fail_bad_object_param_qualifiers_by_value.carbon:[[@LINE+29]]:3: note: in thunk for C++ function used here [InCppThunk]
// CHECK:STDERR: fail_bad_object_param_qualifiers_by_value.carbon:[[@LINE+21]]:3: note: in thunk for C++ function used here [InCppThunk]
// CHECK:STDERR: v.const_ref_ref_this();
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
@@ -100,14 +100,6 @@ fn Value(v: Cpp.HasQualifiers) {
// CHECK:STDERR: 7 | void ref_this() &;
// CHECK:STDERR: | ^
// CHECK:STDERR:
// CHECK:STDERR: fail_bad_object_param_qualifiers_by_value.carbon:[[@LINE+8]]:3: error: cannot implicitly convert expression of type `Cpp.HasQualifiers` to `const Cpp.HasQualifiers` [ConversionFailure]
// CHECK:STDERR: v.const_ref_ref_this();
// CHECK:STDERR: ^
// CHECK:STDERR: fail_bad_object_param_qualifiers_by_value.carbon:[[@LINE+5]]:3: note: type `Cpp.HasQualifiers` does not implement interface `Core.ImplicitAs(const Cpp.HasQualifiers)` [MissingImplInMemberAccessNote]
// CHECK:STDERR: v.const_ref_ref_this();
// CHECK:STDERR: ^
// CHECK:STDERR: fail_bad_object_param_qualifiers_by_value.carbon: note: initializing function parameter [InCallToFunctionParam]
// CHECK:STDERR:
v.const_ref_ref_this();
}