Files
carbon-lang/toolchain/check/testdata/pointer/fail_address_of_value.carbon
T
fdb188ccfd Implement unused pattern bindings, continued (#6518)
Implementation of unused pattern bindings #2022, continued.

Whereas previous PR #6460 took care of parsing, and PR #6479 prepared
the stage by using _ in some test cases, this PR has the the actual
implementation, using a simple dataflow analysis.

---------

Co-authored-by: Burak Emir <bqe@google.com>
Co-authored-by: jonmeow <jperkins@google.com>
2026-02-19 23:33:36 +00:00

104 lines
3.9 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/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]]:33: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR: var unused param_addr: i32* = &param;
// CHECK:STDERR: ^
// CHECK:STDERR:
var unused param_addr: i32* = &param;
}