mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Add a bit more structure to interop/cpp tests. (#7085)
Add import/ and export/ under function/. Move most top-level tests to a new basics/ with subdirectories for `import` directives and `inline Cpp`. Add subdirectory for primitive type handling. Move all `reverse/` tests to somewhere else, typically under an `export/` directory. I split two test files up: constexpr.carbon got split into var/ and function/ pieces, and reverse/simple.carbon was inlined into namespace/export.carbon. The rest are just simple renames.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
// 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/none.carbon
|
||||
// EXTRA-ARGS: --clang-arg=-include-pch --clang-arg=does_not_exist.pch
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/basics/bad_flags.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/bad_flags.carbon
|
||||
// CHECK:STDERR: error: unable to read PCH file does_not_exist.pch: 'No such file or directory' [CppInteropParseError]
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: error: PCH file 'does_not_exist.pch' not found: module file not found [CppInteropParseError]
|
||||
// CHECK:STDERR:
|
||||
|
||||
// --- fail_bad_args.carbon
|
||||
|
||||
import Cpp inline "";
|
||||
|
||||
// Nothing to see here. We're just checking that this does not crash.
|
||||
@@ -0,0 +1,478 @@
|
||||
// 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/none.carbon
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/basics/cpp_diagnostics.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/cpp_diagnostics.carbon
|
||||
|
||||
// ============================================================================
|
||||
// One error
|
||||
// ============================================================================
|
||||
|
||||
// --- one_error.h
|
||||
|
||||
#error "error1"
|
||||
|
||||
// --- fail_import_cpp_file_with_one_error.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_import_cpp_file_with_one_error.carbon:[[@LINE+5]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./one_error.h:2:2: error: "error1" [CppInteropParseError]
|
||||
// CHECK:STDERR: 2 | #error "error1"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "one_error.h";
|
||||
|
||||
// ============================================================================
|
||||
// Multiple errors
|
||||
// ============================================================================
|
||||
|
||||
// --- multiple_errors.h
|
||||
|
||||
#error "error1"
|
||||
#error "error2"
|
||||
|
||||
// --- fail_import_cpp_file_with_multiple_errors.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_import_cpp_file_with_multiple_errors.carbon:[[@LINE+10]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./multiple_errors.h:2:2: error: "error1" [CppInteropParseError]
|
||||
// CHECK:STDERR: 2 | #error "error1"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_import_cpp_file_with_multiple_errors.carbon:[[@LINE+5]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./multiple_errors.h:3:2: error: "error2" [CppInteropParseError]
|
||||
// CHECK:STDERR: 3 | #error "error2"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "multiple_errors.h";
|
||||
|
||||
// ============================================================================
|
||||
// One warning
|
||||
// ============================================================================
|
||||
|
||||
// --- one_warning.h
|
||||
|
||||
#warning "warning1"
|
||||
|
||||
// --- import_cpp_file_with_one_warning.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
//@dump-sem-ir-begin
|
||||
// CHECK:STDERR: import_cpp_file_with_one_warning.carbon:[[@LINE+5]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./one_warning.h:2:2: warning: "warning1" [CppInteropParseWarning]
|
||||
// CHECK:STDERR: 2 | #warning "warning1"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "one_warning.h";
|
||||
//@dump-sem-ir-end
|
||||
|
||||
// ============================================================================
|
||||
// Multiple warnings
|
||||
// ============================================================================
|
||||
|
||||
// --- multiple_warnings.h
|
||||
|
||||
#warning "warning1"
|
||||
#warning "warning2"
|
||||
#warning "warning3"
|
||||
|
||||
// --- import_cpp_file_with_multiple_warnings.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
//@dump-sem-ir-begin
|
||||
// CHECK:STDERR: import_cpp_file_with_multiple_warnings.carbon:[[@LINE+15]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./multiple_warnings.h:2:2: warning: "warning1" [CppInteropParseWarning]
|
||||
// CHECK:STDERR: 2 | #warning "warning1"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: import_cpp_file_with_multiple_warnings.carbon:[[@LINE+10]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./multiple_warnings.h:3:2: warning: "warning2" [CppInteropParseWarning]
|
||||
// CHECK:STDERR: 3 | #warning "warning2"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: import_cpp_file_with_multiple_warnings.carbon:[[@LINE+5]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./multiple_warnings.h:4:2: warning: "warning3" [CppInteropParseWarning]
|
||||
// CHECK:STDERR: 4 | #warning "warning3"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "multiple_warnings.h";
|
||||
//@dump-sem-ir-end
|
||||
|
||||
// ============================================================================
|
||||
// One error and one warning
|
||||
// ============================================================================
|
||||
|
||||
// --- one_error_and_one_warning.h
|
||||
|
||||
#error "error1"
|
||||
#warning "warning1"
|
||||
|
||||
// --- fail_import_cpp_file_with_one_error_and_one_warning.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_import_cpp_file_with_one_error_and_one_warning.carbon:[[@LINE+10]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./one_error_and_one_warning.h:2:2: error: "error1" [CppInteropParseError]
|
||||
// CHECK:STDERR: 2 | #error "error1"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_import_cpp_file_with_one_error_and_one_warning.carbon:[[@LINE+5]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./one_error_and_one_warning.h:3:2: warning: "warning1" [CppInteropParseWarning]
|
||||
// CHECK:STDERR: 3 | #warning "warning1"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "one_error_and_one_warning.h";
|
||||
|
||||
// ============================================================================
|
||||
// Multiple errors and multiple warnings
|
||||
// ============================================================================
|
||||
|
||||
// --- multiple_errors_and_multiple_warnings.h
|
||||
|
||||
#error "error1"
|
||||
#error "error2"
|
||||
#warning "warning1"
|
||||
#warning "warning2"
|
||||
#warning "warning3"
|
||||
|
||||
// --- fail_import_cpp_file_with_multiple_errors_and_multiple_warnings.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_import_cpp_file_with_multiple_errors_and_multiple_warnings.carbon:[[@LINE+25]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./multiple_errors_and_multiple_warnings.h:2:2: error: "error1" [CppInteropParseError]
|
||||
// CHECK:STDERR: 2 | #error "error1"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_import_cpp_file_with_multiple_errors_and_multiple_warnings.carbon:[[@LINE+20]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./multiple_errors_and_multiple_warnings.h:3:2: error: "error2" [CppInteropParseError]
|
||||
// CHECK:STDERR: 3 | #error "error2"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_import_cpp_file_with_multiple_errors_and_multiple_warnings.carbon:[[@LINE+15]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./multiple_errors_and_multiple_warnings.h:4:2: warning: "warning1" [CppInteropParseWarning]
|
||||
// CHECK:STDERR: 4 | #warning "warning1"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_import_cpp_file_with_multiple_errors_and_multiple_warnings.carbon:[[@LINE+10]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./multiple_errors_and_multiple_warnings.h:5:2: warning: "warning2" [CppInteropParseWarning]
|
||||
// CHECK:STDERR: 5 | #warning "warning2"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_import_cpp_file_with_multiple_errors_and_multiple_warnings.carbon:[[@LINE+5]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./multiple_errors_and_multiple_warnings.h:6:2: warning: "warning3" [CppInteropParseWarning]
|
||||
// CHECK:STDERR: 6 | #warning "warning3"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "multiple_errors_and_multiple_warnings.h";
|
||||
|
||||
// ============================================================================
|
||||
// Multiple files with warnings
|
||||
// ============================================================================
|
||||
|
||||
// --- import_multiple_cpp_files_with_warnings.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
//@dump-sem-ir-begin
|
||||
// CHECK:STDERR: import_multiple_cpp_files_with_warnings.carbon:[[@LINE+5]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./one_warning.h:2:2: warning: "warning1" [CppInteropParseWarning]
|
||||
// CHECK:STDERR: 2 | #warning "warning1"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "one_warning.h";
|
||||
// CHECK:STDERR: import_multiple_cpp_files_with_warnings.carbon:[[@LINE+15]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./multiple_warnings.h:2:2: warning: "warning1" [CppInteropParseWarning]
|
||||
// CHECK:STDERR: 2 | #warning "warning1"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: import_multiple_cpp_files_with_warnings.carbon:[[@LINE+10]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./multiple_warnings.h:3:2: warning: "warning2" [CppInteropParseWarning]
|
||||
// CHECK:STDERR: 3 | #warning "warning2"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: import_multiple_cpp_files_with_warnings.carbon:[[@LINE+5]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./multiple_warnings.h:4:2: warning: "warning3" [CppInteropParseWarning]
|
||||
// CHECK:STDERR: 4 | #warning "warning3"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "multiple_warnings.h";
|
||||
//@dump-sem-ir-end
|
||||
|
||||
// ============================================================================
|
||||
// Multiple files with errors and warnings
|
||||
// ============================================================================
|
||||
|
||||
// --- fail_import_multiple_cpp_files_with_errors_and_warnings.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_import_multiple_cpp_files_with_errors_and_warnings.carbon:[[@LINE+10]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./one_error_and_one_warning.h:2:2: error: "error1" [CppInteropParseError]
|
||||
// CHECK:STDERR: 2 | #error "error1"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_import_multiple_cpp_files_with_errors_and_warnings.carbon:[[@LINE+5]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./one_error_and_one_warning.h:3:2: warning: "warning1" [CppInteropParseWarning]
|
||||
// CHECK:STDERR: 3 | #warning "warning1"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "one_error_and_one_warning.h";
|
||||
// CHECK:STDERR: fail_import_multiple_cpp_files_with_errors_and_warnings.carbon:[[@LINE+25]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./multiple_errors_and_multiple_warnings.h:2:2: error: "error1" [CppInteropParseError]
|
||||
// CHECK:STDERR: 2 | #error "error1"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_import_multiple_cpp_files_with_errors_and_warnings.carbon:[[@LINE+20]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./multiple_errors_and_multiple_warnings.h:3:2: error: "error2" [CppInteropParseError]
|
||||
// CHECK:STDERR: 3 | #error "error2"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_import_multiple_cpp_files_with_errors_and_warnings.carbon:[[@LINE+15]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./multiple_errors_and_multiple_warnings.h:4:2: warning: "warning1" [CppInteropParseWarning]
|
||||
// CHECK:STDERR: 4 | #warning "warning1"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_import_multiple_cpp_files_with_errors_and_warnings.carbon:[[@LINE+10]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./multiple_errors_and_multiple_warnings.h:5:2: warning: "warning2" [CppInteropParseWarning]
|
||||
// CHECK:STDERR: 5 | #warning "warning2"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_import_multiple_cpp_files_with_errors_and_warnings.carbon:[[@LINE+5]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./multiple_errors_and_multiple_warnings.h:6:2: warning: "warning3" [CppInteropParseWarning]
|
||||
// CHECK:STDERR: 6 | #warning "warning3"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "multiple_errors_and_multiple_warnings.h";
|
||||
|
||||
// ============================================================================
|
||||
// Indirect error
|
||||
// ============================================================================
|
||||
|
||||
// --- indirect_error.h
|
||||
|
||||
#include "one_error.h"
|
||||
|
||||
// --- fail_import_indirect_error.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_import_indirect_error.carbon:[[@LINE+6]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./indirect_error.h:2:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./one_error.h:2:2: error: "error1" [CppInteropParseError]
|
||||
// CHECK:STDERR: 2 | #error "error1"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "indirect_error.h";
|
||||
|
||||
// ============================================================================
|
||||
// Indirect warning
|
||||
// ============================================================================
|
||||
|
||||
// --- indirect_warning.h
|
||||
|
||||
#include "one_warning.h"
|
||||
|
||||
// --- import_indirect_warning.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
//@dump-sem-ir-begin
|
||||
// CHECK:STDERR: import_indirect_warning.carbon:[[@LINE+6]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./indirect_warning.h:2:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./one_warning.h:2:2: warning: "warning1" [CppInteropParseWarning]
|
||||
// CHECK:STDERR: 2 | #warning "warning1"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "indirect_warning.h";
|
||||
//@dump-sem-ir-end
|
||||
|
||||
// ============================================================================
|
||||
// Lexer error before import
|
||||
// ============================================================================
|
||||
|
||||
// --- fail_import_cpp_library_lexer_error.carbon
|
||||
|
||||
library "[[@TEST_NAME]]"; // Trailing comment
|
||||
|
||||
// TODO: Move this warning to be after the lexer trailing comment error.
|
||||
// CHECK:STDERR: fail_import_cpp_library_lexer_error.carbon:[[@LINE+9]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./one_warning.h:2:2: warning: "warning1" [CppInteropParseWarning]
|
||||
// CHECK:STDERR: 2 | #warning "warning1"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_import_cpp_library_lexer_error.carbon:[[@LINE-8]]:44: error: trailing comments are not permitted [TrailingComment]
|
||||
// CHECK:STDERR: library "import_cpp_library_lexer_error"; // Trailing comment
|
||||
// CHECK:STDERR: ^
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "one_warning.h";
|
||||
|
||||
// ============================================================================
|
||||
// Diagnostic with fix-it hints
|
||||
// ============================================================================
|
||||
|
||||
// --- fix_it_hints.h
|
||||
|
||||
double score = 0.1
|
||||
|
||||
// --- fail_import_fix_it_hints.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_import_fix_it_hints.carbon:[[@LINE+6]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./fix_it_hints.h:2:19: error: expected ';' after top level declarator [CppInteropParseError]
|
||||
// CHECK:STDERR: 2 | double score = 0.1
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR: | ;
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "fix_it_hints.h";
|
||||
|
||||
fn F() {
|
||||
// CHECK:STDERR: fail_import_fix_it_hints.carbon:[[@LINE+4]]:3: error: member name `foo` not found in `Cpp` [MemberNameNotFoundInInstScope]
|
||||
// CHECK:STDERR: Cpp.foo();
|
||||
// CHECK:STDERR: ^~~~~~~
|
||||
// CHECK:STDERR:
|
||||
Cpp.foo();
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Diagnostic with notes
|
||||
// ============================================================================
|
||||
|
||||
// --- with_notes.h
|
||||
|
||||
void foobar(int);
|
||||
|
||||
inline void call_foobar() {
|
||||
foobar(1, 2);
|
||||
}
|
||||
|
||||
// --- fail_with_notes.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_with_notes.carbon:[[@LINE+9]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./with_notes.h:5:3: error: no matching function for call to 'foobar' [CppInteropParseError]
|
||||
// CHECK:STDERR: 5 | foobar(1, 2);
|
||||
// CHECK:STDERR: | ^~~~~~
|
||||
// CHECK:STDERR: fail_with_notes.carbon:[[@LINE+5]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./with_notes.h:2:6: note: candidate function not viable: requires 1 argument, but 2 were provided [CppInteropParseNote]
|
||||
// CHECK:STDERR: 2 | void foobar(int);
|
||||
// CHECK:STDERR: | ^ ~~~
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "with_notes.h";
|
||||
|
||||
fn F() {
|
||||
Cpp.call_foobar();
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Context stacks
|
||||
// ============================================================================
|
||||
|
||||
// --- indirect_include.h
|
||||
|
||||
#define FOO BAR
|
||||
#define BAZ void f(error);
|
||||
|
||||
FOO
|
||||
|
||||
// --- direct_include.h
|
||||
|
||||
#define BAR BAZ
|
||||
|
||||
#include "indirect_include.h"
|
||||
|
||||
// --- fail_use_context_stack.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_use_context_stack.carbon:[[@LINE+15]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./direct_include.h:4:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./indirect_include.h:2:13: in expansion of macro defined here [InCppMacroExpansion]
|
||||
// CHECK:STDERR: ./direct_include.h:2:13: in expansion of macro defined here [InCppMacroExpansion]
|
||||
// CHECK:STDERR: ./indirect_include.h:3:20: in expansion of macro defined here [InCppMacroExpansion]
|
||||
// CHECK:STDERR: ./indirect_include.h:5:1: error: unknown type name 'error' [CppInteropParseError]
|
||||
// CHECK:STDERR: 5 | FOO
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR: 2 | #define FOO BAR
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR: 2 | #define BAR BAZ
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR: 3 | #define BAZ void f(error);
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "direct_include.h";
|
||||
|
||||
// ============================================================================
|
||||
// Diagnostic location in inline code.
|
||||
// ============================================================================
|
||||
|
||||
// --- fail_loc_in_inline_simple.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_loc_in_inline_simple.carbon:[[@LINE+4]]:9: error: use of undeclared identifier 'banana' [CppInteropParseError]
|
||||
// CHECK:STDERR: 8 | int n = banana;
|
||||
// CHECK:STDERR: | ^~~~~~
|
||||
// CHECK:STDERR:
|
||||
import Cpp inline "int n = banana;";
|
||||
|
||||
// --- fail_loc_in_inline_block.carbon
|
||||
|
||||
import Cpp inline '''c++
|
||||
void f(const int n) {
|
||||
// CHECK:STDERR: fail_loc_in_inline_block.carbon:[[@LINE+7]]:3: error: cannot assign to variable 'n' with const-qualified type 'const int' [CppInteropParseError]
|
||||
// CHECK:STDERR: 11 | ++n;
|
||||
// CHECK:STDERR: | ^ ~
|
||||
// CHECK:STDERR: fail_loc_in_inline_block.carbon:[[@LINE-4]]:18: note: variable 'n' declared const here [CppInteropParseNote]
|
||||
// CHECK:STDERR: 3 | void f(const int n) {
|
||||
// CHECK:STDERR: | ~~~~~~~~~~^
|
||||
// CHECK:STDERR:
|
||||
++n;
|
||||
}
|
||||
''';
|
||||
|
||||
// CHECK:STDOUT: --- import_cpp_file_with_one_warning.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: %Cpp.import_cpp = import_cpp {
|
||||
// CHECK:STDOUT: import Cpp "one_warning.h"
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: --- import_cpp_file_with_multiple_warnings.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: %Cpp.import_cpp = import_cpp {
|
||||
// CHECK:STDOUT: import Cpp "multiple_warnings.h"
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: --- import_multiple_cpp_files_with_warnings.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: %Cpp.import_cpp = import_cpp {
|
||||
// CHECK:STDOUT: import Cpp "one_warning.h"
|
||||
// CHECK:STDOUT: import Cpp "multiple_warnings.h"
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: --- import_indirect_warning.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: %Cpp.import_cpp = import_cpp {
|
||||
// CHECK:STDOUT: import Cpp "indirect_warning.h"
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
@@ -0,0 +1,100 @@
|
||||
// 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/none.carbon
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/basics/import/bad_import.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/import/bad_import.carbon
|
||||
|
||||
// --- fail_import_cpp_library_empty.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_import_cpp_library_empty.carbon:[[@LINE+4]]:10: error: empty filename [CppInteropParseError]
|
||||
// CHECK:STDERR: 8 | #include ""
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "";
|
||||
|
||||
// --- fail_import_cpp_library_file_with_quotes.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_import_cpp_library_file_with_quotes.carbon:[[@LINE+4]]:10: error: '\"foo.h\"' file not found [CppInteropParseError]
|
||||
// CHECK:STDERR: 8 | #include "\"foo.h\""
|
||||
// CHECK:STDERR: | ^~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "\"foo.h\"";
|
||||
|
||||
// --- todo_fail_unterminated_import_inline.carbon
|
||||
|
||||
import Cpp inline '''c++
|
||||
void f() {
|
||||
''';
|
||||
|
||||
// TODO: We should diagnose that the inline C++ code didn't leave us at the top
|
||||
// level.
|
||||
|
||||
import Cpp inline '''c++
|
||||
}
|
||||
''';
|
||||
|
||||
// --- fail_import_cpp_library_without_name_and_inline_without_content.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_import_cpp_library_without_name_and_inline_without_content.carbon:[[@LINE+8]]:20: error: expected a string literal to specify the library name [ExpectedLibraryName]
|
||||
// CHECK:STDERR: import Cpp library inline;
|
||||
// CHECK:STDERR: ^~~~~~
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_import_cpp_library_without_name_and_inline_without_content.carbon:[[@LINE+4]]:20: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
|
||||
// CHECK:STDERR: import Cpp library inline;
|
||||
// CHECK:STDERR: ^~~~~~
|
||||
// CHECK:STDERR:
|
||||
import Cpp library inline;
|
||||
|
||||
// --- fail_import_cpp_library_with_name_and_inline_without_content.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_import_cpp_library_with_name_and_inline_without_content.carbon:[[@LINE+8]]:28: error: `import` declarations must end with a `;` [ExpectedDeclSemi]
|
||||
// CHECK:STDERR: import Cpp library "foo.h" inline;
|
||||
// CHECK:STDERR: ^~~~~~
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_import_cpp_library_with_name_and_inline_without_content.carbon:[[@LINE+4]]:1: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
|
||||
// CHECK:STDERR: import Cpp library "foo.h" inline;
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "foo.h" inline;
|
||||
|
||||
// --- fail_import_cpp_library_without_name_and_inline_with_content.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_import_cpp_library_without_name_and_inline_with_content.carbon:[[@LINE+8]]:20: error: expected a string literal to specify the library name [ExpectedLibraryName]
|
||||
// CHECK:STDERR: import Cpp library inline "";
|
||||
// CHECK:STDERR: ^~~~~~
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_import_cpp_library_without_name_and_inline_with_content.carbon:[[@LINE+4]]:20: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
|
||||
// CHECK:STDERR: import Cpp library inline "";
|
||||
// CHECK:STDERR: ^~~~~~
|
||||
// CHECK:STDERR:
|
||||
import Cpp library inline "";
|
||||
|
||||
// --- fail_import_cpp_library_with_name_and_inline_with_content.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_import_cpp_library_with_name_and_inline_with_content.carbon:[[@LINE+8]]:28: error: `import` declarations must end with a `;` [ExpectedDeclSemi]
|
||||
// CHECK:STDERR: import Cpp library "foo.h" inline "";
|
||||
// CHECK:STDERR: ^~~~~~
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_import_cpp_library_with_name_and_inline_with_content.carbon:[[@LINE+4]]:1: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
|
||||
// CHECK:STDERR: import Cpp library "foo.h" inline "";
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "foo.h" inline "";
|
||||
@@ -0,0 +1,166 @@
|
||||
// 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/none.carbon
|
||||
//
|
||||
// EXTRA-ARGS: --target=aarch64-unknown-linux
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/basics/import/cpp_namespace.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/import/cpp_namespace.carbon
|
||||
|
||||
// --- header.h
|
||||
|
||||
// --- fail_duplicate_cpp_name.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp library "header.h";
|
||||
|
||||
// CHECK:STDERR: fail_duplicate_cpp_name.carbon:[[@LINE+8]]:11: error: `namespace` introducer should be followed by a name [ExpectedDeclName]
|
||||
// CHECK:STDERR: namespace Cpp;
|
||||
// CHECK:STDERR: ^~~
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_duplicate_cpp_name.carbon:[[@LINE+4]]:11: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
|
||||
// CHECK:STDERR: namespace Cpp;
|
||||
// CHECK:STDERR: ^~~
|
||||
// CHECK:STDERR:
|
||||
namespace Cpp;
|
||||
|
||||
// --- fail_cpp_in_inner_namespace.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp library "header.h";
|
||||
|
||||
namespace N;
|
||||
// CHECK:STDERR: fail_cpp_in_inner_namespace.carbon:[[@LINE+8]]:13: error: `.` should be followed by a name [ExpectedDeclNameAfterPeriod]
|
||||
// CHECK:STDERR: namespace N.Cpp;
|
||||
// CHECK:STDERR: ^~~
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_cpp_in_inner_namespace.carbon:[[@LINE+4]]:13: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
|
||||
// CHECK:STDERR: namespace N.Cpp;
|
||||
// CHECK:STDERR: ^~~
|
||||
// CHECK:STDERR:
|
||||
namespace N.Cpp;
|
||||
|
||||
// --- alias.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp library "header.h";
|
||||
|
||||
//@dump-sem-ir-begin
|
||||
alias MyCpp = Cpp;
|
||||
//@dump-sem-ir-end
|
||||
|
||||
// --- fail_add_name_to_cpp_namespace.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp library "header.h";
|
||||
|
||||
// CHECK:STDERR: fail_add_name_to_cpp_namespace.carbon:[[@LINE+8]]:7: error: `class` introducer should be followed by a name [ExpectedDeclName]
|
||||
// CHECK:STDERR: class Cpp.C {};
|
||||
// CHECK:STDERR: ^~~
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_add_name_to_cpp_namespace.carbon:[[@LINE+4]]:7: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
|
||||
// CHECK:STDERR: class Cpp.C {};
|
||||
// CHECK:STDERR: ^~~
|
||||
// CHECK:STDERR:
|
||||
class Cpp.C {};
|
||||
|
||||
// --- api_and_impl.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
//@dump-sem-ir-begin
|
||||
import Cpp library "header.h";
|
||||
//@dump-sem-ir-end
|
||||
|
||||
// --- api_and_impl.impl.carbon
|
||||
|
||||
impl library "[[@TEST_NAME]]";
|
||||
|
||||
//@dump-sem-ir-begin
|
||||
import Cpp library "header.h";
|
||||
//@dump-sem-ir-end
|
||||
|
||||
|
||||
// --- /usr/include/system_header.h
|
||||
|
||||
auto system_function() -> void;
|
||||
|
||||
// --- system_header.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
//@dump-sem-ir-begin
|
||||
import Cpp library "<system_header.h>";
|
||||
//@dump-sem-ir-end
|
||||
|
||||
fn F() {
|
||||
//@dump-sem-ir-begin
|
||||
Cpp.system_function();
|
||||
//@dump-sem-ir-end
|
||||
}
|
||||
|
||||
// CHECK:STDOUT: --- alias.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: imports {
|
||||
// CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
|
||||
// CHECK:STDOUT: import Cpp//...
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %MyCpp: <namespace> = alias_binding MyCpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: --- api_and_impl.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: %Cpp.import_cpp = import_cpp {
|
||||
// CHECK:STDOUT: import Cpp "header.h"
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: --- api_and_impl.impl.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: --- system_header.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
|
||||
// CHECK:STDOUT: %system_function.cpp_overload_set.type: type = cpp_overload_set_type @system_function.cpp_overload_set [concrete]
|
||||
// CHECK:STDOUT: %system_function.cpp_overload_set.value: %system_function.cpp_overload_set.type = cpp_overload_set_value @system_function.cpp_overload_set [concrete]
|
||||
// CHECK:STDOUT: %system_function.type: type = fn_type @system_function [concrete]
|
||||
// CHECK:STDOUT: %system_function: %system_function.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: imports {
|
||||
// CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
|
||||
// CHECK:STDOUT: .system_function = %system_function.cpp_overload_set.value
|
||||
// CHECK:STDOUT: import Cpp//...
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %system_function.cpp_overload_set.value: %system_function.cpp_overload_set.type = cpp_overload_set_value @system_function.cpp_overload_set [concrete = constants.%system_function.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %system_function.decl: %system_function.type = fn_decl @system_function [concrete = constants.%system_function] {} {}
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: %Cpp.import_cpp = import_cpp {
|
||||
// CHECK:STDOUT: import Cpp "<system_header.h>"
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @F() {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %system_function.ref: %system_function.cpp_overload_set.type = name_ref system_function, imports.%system_function.cpp_overload_set.value [concrete = constants.%system_function.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %system_function.call: init %empty_tuple.type = call imports.%system_function.decl()
|
||||
// CHECK:STDOUT: <elided>
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
@@ -0,0 +1,18 @@
|
||||
// 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/none.carbon
|
||||
// ARGS: --include-diagnostic-kind --fuzzing compile --no-prelude-import --dump-sem-ir-ranges=only --phase=check %s
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/basics/import/fail_fuzzing.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/import/fail_fuzzing.carbon
|
||||
|
||||
// CHECK:STDERR: fail_fuzzing.carbon:[[@LINE+4]]:1: error: `Cpp` import found during fuzzing [CppInteropFuzzing]
|
||||
// CHECK:STDERR: import Cpp library "file.h";
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "file.h";
|
||||
@@ -0,0 +1,21 @@
|
||||
// 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/none.carbon
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/basics/import/file_not_found.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/import/file_not_found.carbon
|
||||
|
||||
// --- fail_cpp_file_not_found.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_cpp_file_not_found.carbon:[[@LINE+4]]:10: error: 'not_found.h' file not found [CppInteropParseError]
|
||||
// CHECK:STDERR: 8 | #include "not_found.h"
|
||||
// CHECK:STDERR: | ^~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
import Cpp library "not_found.h";
|
||||
@@ -0,0 +1,222 @@
|
||||
// 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/int.carbon
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/basics/import/import.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/import/import.carbon
|
||||
|
||||
// ============================================================================
|
||||
// Import C++ namespace indirectly
|
||||
// ============================================================================
|
||||
|
||||
// --- namespace.h
|
||||
|
||||
namespace MyNamespace {
|
||||
|
||||
class MyClass {};
|
||||
|
||||
} // namespace MyNamespace
|
||||
|
||||
// --- namespace_api.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp library "namespace.h";
|
||||
|
||||
alias MyNamespaceAlias = Cpp.MyNamespace;
|
||||
|
||||
// --- fail_import_namespace_api.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import library "namespace_api";
|
||||
|
||||
fn F() {
|
||||
// Imports are not implicitly re-exported, so lookup is expected to fail.
|
||||
// CHECK:STDERR: fail_import_namespace_api.carbon:[[@LINE+4]]:17: error: member name `MyClass` not found in `Cpp.MyNamespace` [MemberNameNotFoundInInstScope]
|
||||
// CHECK:STDERR: var unused x: MyNamespaceAlias.MyClass;
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
var unused x: MyNamespaceAlias.MyClass;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Import C++ struct indirectly
|
||||
// ============================================================================
|
||||
|
||||
// --- struct.h
|
||||
|
||||
struct MyStruct { void Foo(); };
|
||||
|
||||
// --- struct_api.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp library "struct.h";
|
||||
|
||||
alias MyStructAlias = Cpp.MyStruct;
|
||||
|
||||
// --- fail_todo_import_struct_api.carbon
|
||||
// CHECK:STDERR: fail_todo_import_struct_api.carbon: error: semantics TODO: `Unsupported: Importing C++ indirectly` [SemanticsTodo]
|
||||
// CHECK:STDERR:
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import library "struct_api";
|
||||
|
||||
fn F() {
|
||||
//@dump-sem-ir-begin
|
||||
var x: MyStructAlias;
|
||||
x.Foo();
|
||||
//@dump-sem-ir-end
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Import C++ function indirectly
|
||||
// ============================================================================
|
||||
|
||||
// --- function.h
|
||||
|
||||
auto foo_short(short x) -> void;
|
||||
auto foo_int(int x) -> void;
|
||||
|
||||
// --- function_api.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp library "function.h";
|
||||
|
||||
alias FooShort = Cpp.foo_short;
|
||||
alias FooInt = Cpp.foo_int;
|
||||
|
||||
// --- fail_todo_import_function_api.carbon
|
||||
// CHECK:STDERR: fail_todo_import_function_api.carbon: error: semantics TODO: `Unsupported: Importing C++ function `foo_short` indirectly` [SemanticsTodo]
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_todo_import_function_api.carbon: error: semantics TODO: `Unsupported: Importing C++ function `foo_short` indirectly` [SemanticsTodo]
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_todo_import_function_api.carbon: error: semantics TODO: `Unsupported: Importing C++ function `foo_int` indirectly` [SemanticsTodo]
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_todo_import_function_api.carbon: error: semantics TODO: `Unsupported: Importing C++ function `foo_int` indirectly` [SemanticsTodo]
|
||||
// CHECK:STDERR:
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import library "function_api";
|
||||
|
||||
fn F() {
|
||||
//@dump-sem-ir-begin
|
||||
FooShort(8 as i16);
|
||||
FooInt(9);
|
||||
//@dump-sem-ir-end
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Import Cpp without a header
|
||||
// ============================================================================
|
||||
|
||||
// --- no_header.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp;
|
||||
|
||||
fn F(input: Cpp.int) {
|
||||
let unused output: i32 = input;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Import Cpp without a header, with a header and inline
|
||||
// ============================================================================
|
||||
|
||||
// --- header_function.h
|
||||
|
||||
auto MyHeaderFunction(int) -> void;
|
||||
|
||||
// --- no_header_with_header_inline.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp;
|
||||
import Cpp library "header_function.h";
|
||||
import Cpp inline '''
|
||||
auto MyInlineFunction(short) -> void;
|
||||
''';
|
||||
|
||||
fn F() {
|
||||
Cpp.MyHeaderFunction(8 as Cpp.int);
|
||||
Cpp.MyInlineFunction(9 as Cpp.short);
|
||||
}
|
||||
|
||||
// CHECK:STDOUT: --- fail_todo_import_struct_api.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: imports {
|
||||
// CHECK:STDOUT: %Main.MyStructAlias: type = import_ref Main//struct_api, MyStructAlias, loaded [concrete = <error>]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @F() {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: name_binding_decl {
|
||||
// CHECK:STDOUT: %x.patt: <error> = ref_binding_pattern x [concrete]
|
||||
// CHECK:STDOUT: %x.var_patt: <error> = var_pattern %x.patt [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %x.var: ref <error> = var %x.var_patt [concrete = <error>]
|
||||
// CHECK:STDOUT: assign %x.var, <error>
|
||||
// CHECK:STDOUT: %MyStructAlias.ref: type = name_ref MyStructAlias, imports.%Main.MyStructAlias [concrete = <error>]
|
||||
// CHECK:STDOUT: %x: ref <error> = ref_binding x, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %x.ref: ref <error> = name_ref x, %x [concrete = <error>]
|
||||
// CHECK:STDOUT: %Foo.ref: <error> = name_ref Foo, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: <elided>
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: --- fail_todo_import_function_api.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %int_8.b85: Core.IntLiteral = int_value 8 [concrete]
|
||||
// CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete]
|
||||
// CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete]
|
||||
// CHECK:STDOUT: %As.type.359: type = facet_type <@As, @As(%i16)> [concrete]
|
||||
// CHECK:STDOUT: %To: Core.IntLiteral = symbolic_binding To, 0 [symbolic]
|
||||
// CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.type.09e: type = fn_type @Core.IntLiteral.as.As.impl.Convert, @Core.IntLiteral.as.As.impl(%To) [symbolic]
|
||||
// CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.dbe: %Core.IntLiteral.as.As.impl.Convert.type.09e = struct_value () [symbolic]
|
||||
// CHECK:STDOUT: %As.impl_witness.b61: <witness> = impl_witness imports.%As.impl_witness_table.9fc, @Core.IntLiteral.as.As.impl(%int_16) [concrete]
|
||||
// CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.type.c60: type = fn_type @Core.IntLiteral.as.As.impl.Convert, @Core.IntLiteral.as.As.impl(%int_16) [concrete]
|
||||
// CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.a42: %Core.IntLiteral.as.As.impl.Convert.type.c60 = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %As.facet: %As.type.359 = facet_value Core.IntLiteral, (%As.impl_witness.b61) [concrete]
|
||||
// CHECK:STDOUT: %As.WithSelf.Convert.type.2c0: type = fn_type @As.WithSelf.Convert, @As.WithSelf(%i16, %As.facet) [concrete]
|
||||
// CHECK:STDOUT: %.70c: type = fn_type_with_self_type %As.WithSelf.Convert.type.2c0, %As.facet [concrete]
|
||||
// CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.bound: <bound method> = bound_method %int_8.b85, %Core.IntLiteral.as.As.impl.Convert.a42 [concrete]
|
||||
// CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.specific_fn: <specific function> = specific_function %Core.IntLiteral.as.As.impl.Convert.a42, @Core.IntLiteral.as.As.impl.Convert(%int_16) [concrete]
|
||||
// CHECK:STDOUT: %bound_method: <bound method> = bound_method %int_8.b85, %Core.IntLiteral.as.As.impl.Convert.specific_fn [concrete]
|
||||
// CHECK:STDOUT: %int_8.823: %i16 = int_value 8 [concrete]
|
||||
// CHECK:STDOUT: %int_9: Core.IntLiteral = int_value 9 [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: imports {
|
||||
// CHECK:STDOUT: %Main.FooShort: <error> = import_ref Main//function_api, FooShort, loaded [concrete = <error>]
|
||||
// CHECK:STDOUT: %Main.FooInt: <error> = import_ref Main//function_api, FooInt, loaded [concrete = <error>]
|
||||
// CHECK:STDOUT: %Core.import_ref.ca0: @Core.IntLiteral.as.As.impl.%Core.IntLiteral.as.As.impl.Convert.type (%Core.IntLiteral.as.As.impl.Convert.type.09e) = import_ref Core//prelude/parts/int, loc{{\d+_\d+}}, loaded [symbolic = @Core.IntLiteral.as.As.impl.%Core.IntLiteral.as.As.impl.Convert (constants.%Core.IntLiteral.as.As.impl.Convert.dbe)]
|
||||
// CHECK:STDOUT: %As.impl_witness_table.9fc = impl_witness_table (%Core.import_ref.ca0), @Core.IntLiteral.as.As.impl [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @F() {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: %FooShort.ref: <error> = name_ref FooShort, imports.%Main.FooShort [concrete = <error>]
|
||||
// CHECK:STDOUT: %int_8: Core.IntLiteral = int_value 8 [concrete = constants.%int_8.b85]
|
||||
// CHECK:STDOUT: %i16: type = type_literal constants.%i16 [concrete = constants.%i16]
|
||||
// CHECK:STDOUT: %impl.elem0: %.70c = impl_witness_access constants.%As.impl_witness.b61, element0 [concrete = constants.%Core.IntLiteral.as.As.impl.Convert.a42]
|
||||
// CHECK:STDOUT: %bound_method.loc16_14.1: <bound method> = bound_method %int_8, %impl.elem0 [concrete = constants.%Core.IntLiteral.as.As.impl.Convert.bound]
|
||||
// CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Core.IntLiteral.as.As.impl.Convert(constants.%int_16) [concrete = constants.%Core.IntLiteral.as.As.impl.Convert.specific_fn]
|
||||
// CHECK:STDOUT: %bound_method.loc16_14.2: <bound method> = bound_method %int_8, %specific_fn [concrete = constants.%bound_method]
|
||||
// CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.call: init %i16 = call %bound_method.loc16_14.2(%int_8) [concrete = constants.%int_8.823]
|
||||
// CHECK:STDOUT: %.loc16_14.1: %i16 = value_of_initializer %Core.IntLiteral.as.As.impl.Convert.call [concrete = constants.%int_8.823]
|
||||
// CHECK:STDOUT: %.loc16_14.2: %i16 = converted %int_8, %.loc16_14.1 [concrete = constants.%int_8.823]
|
||||
// CHECK:STDOUT: %FooInt.ref: <error> = name_ref FooInt, imports.%Main.FooInt [concrete = <error>]
|
||||
// CHECK:STDOUT: %int_9: Core.IntLiteral = int_value 9 [concrete = constants.%int_9]
|
||||
// CHECK:STDOUT: <elided>
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
@@ -0,0 +1,36 @@
|
||||
// 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/none.carbon
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/basics/import/include.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/import/include.carbon
|
||||
|
||||
// --- included_file.h
|
||||
|
||||
void foo();
|
||||
|
||||
// --- including_file.h
|
||||
|
||||
#include "included_file.h"
|
||||
|
||||
// --- import_function_decl.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
//@dump-sem-ir-begin
|
||||
import Cpp library "including_file.h";
|
||||
//@dump-sem-ir-end
|
||||
|
||||
// CHECK:STDOUT: --- import_function_decl.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: %Cpp.import_cpp = import_cpp {
|
||||
// CHECK:STDOUT: import Cpp "including_file.h"
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
@@ -0,0 +1,39 @@
|
||||
// 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/uint.carbon
|
||||
// EXTRA-ARGS: --target=x86_64-linux-gnu
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/basics/import/include_paths.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/import/include_paths.carbon
|
||||
|
||||
// --- include_stddef.h
|
||||
|
||||
// Check that include paths are properly set up when running Clang.
|
||||
|
||||
// Clang provides <stddef.h> as a builtin header.
|
||||
#include <stddef.h>
|
||||
|
||||
ptrdiff_t GetSize();
|
||||
|
||||
// --- import_stddef_indirectly.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp library "include_stddef.h";
|
||||
|
||||
fn CallGetSize() -> Cpp.ptrdiff_t {
|
||||
return Cpp.GetSize();
|
||||
}
|
||||
|
||||
// --- import_stddef_directly.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp library "stddef.h";
|
||||
|
||||
var n: Cpp.size_t = 42;
|
||||
@@ -0,0 +1,38 @@
|
||||
// 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/none.carbon
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/basics/import/multiple_imports.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/import/multiple_imports.carbon
|
||||
|
||||
// --- file1.h
|
||||
|
||||
void foo1();
|
||||
|
||||
// --- file2.h
|
||||
|
||||
void foo1();
|
||||
|
||||
// --- multiple_imports.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
//@dump-sem-ir-begin
|
||||
import Cpp library "file1.h";
|
||||
import Cpp library "file2.h";
|
||||
//@dump-sem-ir-end
|
||||
|
||||
// CHECK:STDOUT: --- multiple_imports.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: %Cpp.import_cpp = import_cpp {
|
||||
// CHECK:STDOUT: import Cpp "file1.h"
|
||||
// CHECK:STDOUT: import Cpp "file2.h"
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
@@ -0,0 +1,141 @@
|
||||
// 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/none.carbon
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/basics/inline/decl.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/inline/decl.carbon
|
||||
|
||||
// --- inline_decl.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp;
|
||||
|
||||
inline Cpp '''
|
||||
void func1() {}
|
||||
''';
|
||||
|
||||
fn Run1() {
|
||||
Cpp.func1();
|
||||
}
|
||||
|
||||
inline Cpp '''
|
||||
void func2() {
|
||||
Carbon::Run1();
|
||||
}
|
||||
''';
|
||||
|
||||
fn Run2() {
|
||||
Cpp.func2();
|
||||
}
|
||||
|
||||
// --- fail_redefinition.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp;
|
||||
|
||||
inline Cpp '''
|
||||
void f() {}
|
||||
''';
|
||||
|
||||
inline Cpp '''
|
||||
// CHECK:STDERR: fail_redefinition.carbon:[[@LINE+7]]:6: error: redefinition of 'f' [CppInteropParseError]
|
||||
// CHECK:STDERR: 18 | void f() {}
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR: fail_redefinition.carbon:[[@LINE-7]]:6: note: previous definition is here [CppInteropParseNote]
|
||||
// CHECK:STDERR: 7 | void f() {}
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
void f() {}
|
||||
''';
|
||||
|
||||
// --- fail_diag_location.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp;
|
||||
|
||||
// CHECK:STDERR: fail_diag_location.carbon:[[@LINE+4]]:12: error: use of undeclared identifier 'undeclared' [CppInteropParseError]
|
||||
// CHECK:STDERR: 10 | void f() { undeclared = 0; }
|
||||
// CHECK:STDERR: | ^~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
inline Cpp "void f() { undeclared = 0; }";
|
||||
|
||||
inline Cpp '''
|
||||
void g() {
|
||||
// CHECK:STDERR: fail_diag_location.carbon:[[@LINE+4]]:3: error: use of undeclared identifier 'undeclared' [CppInteropParseError]
|
||||
// CHECK:STDERR: 18 | undeclared = 0;
|
||||
// CHECK:STDERR: | ^~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
undeclared = 0;
|
||||
}
|
||||
''';
|
||||
|
||||
// --- fail_inline_no_import.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_inline_no_import.carbon:[[@LINE+4]]:8: error: name `Cpp` not found [NameNotFound]
|
||||
// CHECK:STDERR: inline Cpp "";
|
||||
// CHECK:STDERR: ^~~
|
||||
// CHECK:STDERR:
|
||||
inline Cpp "";
|
||||
|
||||
// --- fail_nested.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp;
|
||||
|
||||
class C {
|
||||
// CHECK:STDERR: fail_nested.carbon:[[@LINE+4]]:3: error: `inline Cpp` declaration not at file scope [InlineDeclNotAtFileScope]
|
||||
// CHECK:STDERR: inline Cpp "";
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
inline Cpp "";
|
||||
}
|
||||
|
||||
interface I {
|
||||
// CHECK:STDERR: fail_nested.carbon:[[@LINE+4]]:3: error: `inline Cpp` declaration not at file scope [InlineDeclNotAtFileScope]
|
||||
// CHECK:STDERR: inline Cpp "";
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
inline Cpp "";
|
||||
}
|
||||
|
||||
constraint N {
|
||||
// CHECK:STDERR: fail_nested.carbon:[[@LINE+4]]:3: error: `inline Cpp` declaration not at file scope [InlineDeclNotAtFileScope]
|
||||
// CHECK:STDERR: inline Cpp "";
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
inline Cpp "";
|
||||
}
|
||||
|
||||
impl C as I {
|
||||
// CHECK:STDERR: fail_nested.carbon:[[@LINE+4]]:3: error: `inline Cpp` declaration not at file scope [InlineDeclNotAtFileScope]
|
||||
// CHECK:STDERR: inline Cpp "";
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
inline Cpp "";
|
||||
}
|
||||
|
||||
// --- fail_nested_fn.carbon
|
||||
|
||||
fn F() {
|
||||
// TODO: Should this be a check error rather than a parse error?
|
||||
// CHECK:STDERR: fail_nested_fn.carbon:[[@LINE+8]]:3: error: expected expression [ExpectedExpr]
|
||||
// CHECK:STDERR: inline Cpp "";
|
||||
// CHECK:STDERR: ^~~~~~
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_nested_fn.carbon:[[@LINE+4]]:3: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
|
||||
// CHECK:STDERR: inline Cpp "";
|
||||
// CHECK:STDERR: ^~~~~~
|
||||
// CHECK:STDERR:
|
||||
inline Cpp "";
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
// 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/none.carbon
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/basics/inline/import.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/inline/import.carbon
|
||||
|
||||
// --- use_inline_function_decl.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
//@dump-sem-ir-begin
|
||||
import Cpp inline '''
|
||||
|
||||
// A C++ function.
|
||||
inline void func() {}
|
||||
|
||||
''';
|
||||
//@dump-sem-ir-end
|
||||
|
||||
fn Run() {
|
||||
//@dump-sem-ir-begin
|
||||
Cpp.func();
|
||||
//@dump-sem-ir-end
|
||||
}
|
||||
|
||||
// --- with_language_marker.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
//@dump-sem-ir-begin
|
||||
import Cpp inline '''c++
|
||||
|
||||
// A C++ function.
|
||||
inline void another_func() {}
|
||||
|
||||
''';
|
||||
//@dump-sem-ir-end
|
||||
|
||||
fn Run() {
|
||||
//@dump-sem-ir-begin
|
||||
Cpp.another_func();
|
||||
//@dump-sem-ir-end
|
||||
}
|
||||
|
||||
// CHECK:STDOUT: --- use_inline_function_decl.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
|
||||
// CHECK:STDOUT: %func.cpp_overload_set.type: type = cpp_overload_set_type @func.cpp_overload_set [concrete]
|
||||
// CHECK:STDOUT: %func.cpp_overload_set.value: %func.cpp_overload_set.type = cpp_overload_set_value @func.cpp_overload_set [concrete]
|
||||
// CHECK:STDOUT: %func.type: type = fn_type @func [concrete]
|
||||
// CHECK:STDOUT: %func: %func.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: imports {
|
||||
// CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
|
||||
// CHECK:STDOUT: .func = %func.cpp_overload_set.value
|
||||
// CHECK:STDOUT: import Cpp//...
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %func.cpp_overload_set.value: %func.cpp_overload_set.type = cpp_overload_set_value @func.cpp_overload_set [concrete = constants.%func.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %func.decl: %func.type = fn_decl @func [concrete = constants.%func] {} {}
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: %Cpp.import_cpp = import_cpp {
|
||||
// CHECK:STDOUT: import Cpp inline
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @Run() {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %func.ref: %func.cpp_overload_set.type = name_ref func, imports.%func.cpp_overload_set.value [concrete = constants.%func.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %func.call: init %empty_tuple.type = call imports.%func.decl()
|
||||
// CHECK:STDOUT: <elided>
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: --- with_language_marker.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
|
||||
// CHECK:STDOUT: %another_func.cpp_overload_set.type: type = cpp_overload_set_type @another_func.cpp_overload_set [concrete]
|
||||
// CHECK:STDOUT: %another_func.cpp_overload_set.value: %another_func.cpp_overload_set.type = cpp_overload_set_value @another_func.cpp_overload_set [concrete]
|
||||
// CHECK:STDOUT: %another_func.type: type = fn_type @another_func [concrete]
|
||||
// CHECK:STDOUT: %another_func: %another_func.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: imports {
|
||||
// CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
|
||||
// CHECK:STDOUT: .another_func = %another_func.cpp_overload_set.value
|
||||
// CHECK:STDOUT: import Cpp//...
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %another_func.cpp_overload_set.value: %another_func.cpp_overload_set.type = cpp_overload_set_value @another_func.cpp_overload_set [concrete = constants.%another_func.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %another_func.decl: %another_func.type = fn_decl @another_func [concrete = constants.%another_func] {} {}
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: %Cpp.import_cpp = import_cpp {
|
||||
// CHECK:STDOUT: import Cpp inline
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @Run() {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %another_func.ref: %another_func.cpp_overload_set.type = name_ref another_func, imports.%another_func.cpp_overload_set.value [concrete = constants.%another_func.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %another_func.call: init %empty_tuple.type = call imports.%another_func.decl()
|
||||
// CHECK:STDOUT: <elided>
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
@@ -0,0 +1,89 @@
|
||||
// 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/none.carbon
|
||||
// EXTRA-ARGS: --clang-arg=--std=c++20
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/basics/inline/modules.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/inline/modules.carbon
|
||||
|
||||
// --- fail_export_module_in_inline_cpp.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// TODO: This diagnostic isn't very good.
|
||||
import Cpp inline '''
|
||||
// CHECK:STDERR: fail_export_module_in_inline_cpp.carbon:[[@LINE+7]]:8: error: module declaration must occur at the start of the translation unit [CppInteropParseError]
|
||||
// CHECK:STDERR: 13 | export module Foo;
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR: <carbon Cpp imports>:1:1: note: add 'module;' to the start of the file to introduce a global module fragment [CppInteropParseNote]
|
||||
// CHECK:STDERR: 1 | # 6 "fail_export_module_in_inline_cpp.carbon"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
export module Foo;
|
||||
''';
|
||||
|
||||
// --- fail_module_in_inline_cpp.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// TODO: This diagnostic isn't very good.
|
||||
import Cpp inline '''
|
||||
// CHECK:STDERR: fail_module_in_inline_cpp.carbon:[[@LINE+11]]:1: error: module declaration must occur at the start of the translation unit [CppInteropParseError]
|
||||
// CHECK:STDERR: 17 | module Foo;
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR: <carbon Cpp imports>:1:1: note: add 'module;' to the start of the file to introduce a global module fragment [CppInteropParseNote]
|
||||
// CHECK:STDERR: 1 | # 6 "fail_module_in_inline_cpp.carbon"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_module_in_inline_cpp.carbon:[[@LINE+4]]:8: error: module 'Foo' not found [CppInteropParseError]
|
||||
// CHECK:STDERR: 17 | module Foo;
|
||||
// CHECK:STDERR: | ^~~~
|
||||
// CHECK:STDERR:
|
||||
module Foo;
|
||||
''';
|
||||
|
||||
// --- fail_global_module_in_inline_cpp.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// TODO: This diagnostic isn't very good.
|
||||
import Cpp inline '''
|
||||
// CHECK:STDERR: fail_global_module_in_inline_cpp.carbon:[[@LINE+4]]:1: error: 'module;' introducing a global module fragment can appear only at the start of the translation unit [CppInteropParseError]
|
||||
// CHECK:STDERR: 10 | module;
|
||||
// CHECK:STDERR: | ^~~~~~~
|
||||
// CHECK:STDERR:
|
||||
module;
|
||||
|
||||
int n;
|
||||
|
||||
// CHECK:STDERR: fail_global_module_in_inline_cpp.carbon:[[@LINE+11]]:1: error: module declaration must occur at the start of the translation unit [CppInteropParseError]
|
||||
// CHECK:STDERR: 25 | module Foo;
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR: <carbon Cpp imports>:1:1: note: add 'module;' to the start of the file to introduce a global module fragment [CppInteropParseNote]
|
||||
// CHECK:STDERR: 1 | # 6 "fail_global_module_in_inline_cpp.carbon"
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_global_module_in_inline_cpp.carbon:[[@LINE+4]]:8: error: module 'Foo' not found [CppInteropParseError]
|
||||
// CHECK:STDERR: 25 | module Foo;
|
||||
// CHECK:STDERR: | ^~~~
|
||||
// CHECK:STDERR:
|
||||
module Foo;
|
||||
''';
|
||||
|
||||
// --- fail_import_in_inline_cpp.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// TODO: Also test that a valid module import works.
|
||||
import Cpp inline '''
|
||||
// CHECK:STDERR: fail_import_in_inline_cpp.carbon:[[@LINE+4]]:8: error: 'file_that_does_not_exist.h' file not found [CppInteropParseError]
|
||||
// CHECK:STDERR: 10 | import "file_that_does_not_exist.h";
|
||||
// CHECK:STDERR: | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
import "file_that_does_not_exist.h";
|
||||
''';
|
||||
@@ -0,0 +1,58 @@
|
||||
// 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/int.carbon
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/basics/unsupported_decl_type.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/unsupported_decl_type.carbon
|
||||
|
||||
// --- structured_binding.h
|
||||
|
||||
struct X { int a, b; };
|
||||
auto [a, b] = X{};
|
||||
|
||||
// --- fail_todo_use_structured_binding.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_todo_use_structured_binding.carbon:[[@LINE+4]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./structured_binding.h:3:7: error: semantics TODO: `Unsupported: Declaration type Binding` [SemanticsTodo]
|
||||
// CHECK:STDERR: auto [a, b] = X{};
|
||||
// CHECK:STDERR: ^
|
||||
import Cpp library "structured_binding.h";
|
||||
|
||||
fn F() -> i32 {
|
||||
//@dump-sem-ir-begin
|
||||
// CHECK:STDERR: fail_todo_use_structured_binding.carbon:[[@LINE+4]]:10: note: in `Cpp` name lookup for `a` [InCppNameLookup]
|
||||
// CHECK:STDERR: return Cpp.a;
|
||||
// CHECK:STDERR: ^~~~~
|
||||
// CHECK:STDERR:
|
||||
return Cpp.a;
|
||||
//@dump-sem-ir-end
|
||||
}
|
||||
|
||||
// CHECK:STDOUT: --- fail_todo_use_structured_binding.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
|
||||
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: imports {
|
||||
// CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
|
||||
// CHECK:STDOUT: .a = <error>
|
||||
// CHECK:STDOUT: import Cpp//...
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @F() -> out %return.param: %i32 {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %a.ref: <error> = name_ref a, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: return <error>
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
@@ -0,0 +1,43 @@
|
||||
// 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/int.carbon
|
||||
// EXTRA-ARGS: --clang-arg=-Wunused
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/basics/unused_internal.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/unused_internal.carbon
|
||||
|
||||
// --- unused.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp inline '''c++
|
||||
// CHECK:STDERR: unused.carbon:[[@LINE+4]]:12: warning: unused variable 'n' [CppInteropParseWarning]
|
||||
// CHECK:STDERR: 9 | static int n = 0;
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
static int n = 0;
|
||||
// CHECK:STDERR: unused.carbon:[[@LINE+4]]:13: warning: unused function 'f' [CppInteropParseWarning]
|
||||
// CHECK:STDERR: 14 | static void f() {}
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
static void f() {}
|
||||
''';
|
||||
|
||||
// --- not_unused.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp inline '''c++
|
||||
static int n = 0;
|
||||
static void f() {}
|
||||
''';
|
||||
|
||||
fn F() -> i32 {
|
||||
Cpp.f();
|
||||
return Cpp.n;
|
||||
}
|
||||
Reference in New Issue
Block a user