You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Based on #5948. A couple of tricky parts:
* When generating the C++ side of the thunk, we are given a pointer to
the location to emplace the return value. The only mechanism C++
provides to perform this emplacement is using placement `operator new`,
which requires a library function in the `<new>` header. We handle this
by declaring that library function ourselves, and rely on Clang not
actually needing a definition for it (which the standard library owns).
* On the Carbon side of the thunk, we want to form an initializing
expression as the result of the call. We don't have a way of expressing
in SemIR that an initializing expression performs its initialization by
storing through a pointer, so this PR adds a new initializing
instruction, `InPlaceInit`, to model an initialization that's performed
opaquely in-place.
Copy file name to clipboardExpand all lines: toolchain/check/testdata/interop/cpp/function/class.carbon
+31-6Lines changed: 31 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -447,13 +447,29 @@ auto foo() -> C;
447
447
448
448
library "[[@TEST_NAME]]";
449
449
450
+
// CHECK:STDERR: fail_import_decl_value_return_type.carbon:[[@LINE+12]]:10: in file included here [InCppInclude]
451
+
// CHECK:STDERR: ./decl_value_return_type.h:4:6: error: calling 'foo' with incomplete return type 'C' [CppInteropParseError]
452
+
// CHECK:STDERR: 4 | auto foo() -> C;
453
+
// CHECK:STDERR: | ^~~
454
+
// CHECK:STDERR: fail_import_decl_value_return_type.carbon:[[@LINE+8]]:10: in file included here [InCppInclude]
455
+
// CHECK:STDERR: ./decl_value_return_type.h:4:6: note: 'foo' declared here [CppInteropParseNote]
456
+
// CHECK:STDERR: 4 | auto foo() -> C;
457
+
// CHECK:STDERR: | ^
458
+
// CHECK:STDERR: fail_import_decl_value_return_type.carbon:[[@LINE+4]]:10: in file included here [InCppInclude]
459
+
// CHECK:STDERR: ./decl_value_return_type.h:2:7: note: forward declaration of 'C' [CppInteropParseNote]
460
+
// CHECK:STDERR: 2 | class C;
461
+
// CHECK:STDERR: | ^
450
462
importCpp library "decl_value_return_type.h";
451
463
452
464
fnF() {
465
+
// CHECK:STDERR: fail_import_decl_value_return_type.carbon:[[@LINE+13]]:3: note: in `Cpp` name lookup for `foo` [InCppNameLookup]
466
+
// CHECK:STDERR: Cpp.foo();
467
+
// CHECK:STDERR: ^~~~~~~
468
+
// CHECK:STDERR:
453
469
// CHECK:STDERR: fail_import_decl_value_return_type.carbon:[[@LINE+9]]:3: error: function returns incomplete type `Cpp.C` [IncompleteTypeInFunctionReturnType]
454
470
// CHECK:STDERR: Cpp.foo();
455
471
// CHECK:STDERR: ^~~~~~~~~
456
-
// CHECK:STDERR: fail_import_decl_value_return_type.carbon:[[@LINE-6]]:10: in file included here [InCppInclude]
472
+
// CHECK:STDERR: fail_import_decl_value_return_type.carbon:[[@LINE-10]]:10: in file included here [InCppInclude]
457
473
// CHECK:STDERR: ./decl_value_return_type.h:2:7: note: class was forward declared here [ClassForwardDeclaredHere]
458
474
// CHECK:STDERR: class C;
459
475
// CHECK:STDERR: ^
@@ -1157,9 +1173,11 @@ fn F() {
1157
1173
// CHECK:STDOUT: %C: type = class_type @C [concrete]
1158
1174
// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete]
0 commit comments