// 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/primitives.carbon // // AUTOUPDATE // TIP: To test this file alone, run: // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/pointer/fail_address_of_value.carbon // TIP: To dump output, run: // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/pointer/fail_address_of_value.carbon fn G() -> i32; fn H() -> {.a: i32}; fn AddressOfLiteral() { // CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef] // CHECK:STDERR: &0; // CHECK:STDERR: ^ // CHECK:STDERR: &0; // CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef] // CHECK:STDERR: &true; // CHECK:STDERR: ^ // CHECK:STDERR: &true; // CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef] // CHECK:STDERR: &1.0; // CHECK:STDERR: ^ // CHECK:STDERR: &1.0; // CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef] // CHECK:STDERR: &"Hello"; // CHECK:STDERR: ^ // CHECK:STDERR: &"Hello"; // CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef] // CHECK:STDERR: &(1, 2); // CHECK:STDERR: ^ // CHECK:STDERR: &(1, 2); // CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef] // CHECK:STDERR: &{.a = 5}; // CHECK:STDERR: ^ // CHECK:STDERR: &{.a = 5}; } fn AddressOfOperator() { // CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef] // CHECK:STDERR: &(true and false); // CHECK:STDERR: ^ // CHECK:STDERR: &(true and false); // CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef] // CHECK:STDERR: &H().a; // CHECK:STDERR: ^ // CHECK:STDERR: &H().a; // CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef] // CHECK:STDERR: &(not true); // CHECK:STDERR: ^ // CHECK:STDERR: &(not true); } fn AddressOfCall() { // CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef] // CHECK:STDERR: &G(); // CHECK:STDERR: ^ // CHECK:STDERR: &G(); } fn AddressOfType() { // CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef] // CHECK:STDERR: &i32; // CHECK:STDERR: ^ // CHECK:STDERR: &i32; // CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef] // CHECK:STDERR: &(const i32*); // CHECK:STDERR: ^ // CHECK:STDERR: &(const i32*); } fn AddressOfTupleElementValue() { // CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef] // CHECK:STDERR: &((1, 2).0); // CHECK:STDERR: ^ // CHECK:STDERR: &((1, 2).0); } fn AddressOfParam(param: i32) { // CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:26: error: cannot take the address of non-reference expression [AddrOfNonRef] // CHECK:STDERR: var param_addr: i32* = ¶m; // CHECK:STDERR: ^ // CHECK:STDERR: var param_addr: i32* = ¶m; }