mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-27 09:51:18 +00:00
When returning a value from a function whose return type has a by-copy initializing representation, perform initialization like we do when the return type has an in-place initializing representation. This makes our SemIR representation more uniform, as the return expression will now always be an initializing expression rather than a value expression, but more importantly it means that attempts to return a non-copyable type by value now fail, even if the type has a by-copy initializing representation. This catches a bunch of places where we were returning a value of an unconstrained template parameter `T:! type`, which we were incorrectly allowing because we didn't notice it was not copyable. Unfortunately this then requires quite a few test updates. Like #6034, this exposes a lowering issue where lowering crashes when attempting to lower a specific copy operation for certain types; a couple more tests are temporarily disabled here. An upcoming PR dependent on this one will fix the issue and re-enable those tests.
42 lines
1.6 KiB
Plaintext
42 lines
1.6 KiB
Plaintext
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/generic/fail_generic_copy.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/generic/fail_generic_copy.carbon
|
|
|
|
// --- fail_return.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
fn F[T:! type](x: T) -> T {
|
|
// CHECK:STDERR: fail_return.carbon:[[@LINE+7]]:10: error: cannot copy value of type `T` [CopyOfUncopyableType]
|
|
// CHECK:STDERR: return x;
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR: fail_return.carbon:[[@LINE+4]]:10: note: type `T` does not implement interface `Core.Copy` [MissingImplInMemberAccessNote]
|
|
// CHECK:STDERR: return x;
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR:
|
|
return x;
|
|
}
|
|
|
|
// --- fail_var.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
fn F[T:! type](x: T) {
|
|
// CHECK:STDERR: fail_var.carbon:[[@LINE+7]]:14: error: cannot copy value of type `T` [CopyOfUncopyableType]
|
|
// CHECK:STDERR: var y: T = x;
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR: fail_var.carbon:[[@LINE+4]]:14: note: type `T` does not implement interface `Core.Copy` [MissingImplInMemberAccessNote]
|
|
// CHECK:STDERR: var y: T = x;
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR:
|
|
var y: T = x;
|
|
}
|