Skip to content

Commit 94bb6be

Browse files
authored
C++ Interop: Make CppVoidType always-incomplete (#6302)
Part of #6280.
1 parent ca3f95f commit 94bb6be

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

toolchain/check/testdata/interop/cpp/function/void_pointer.carbon

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,18 @@ fn F() {
8484
//@dump-sem-ir-end
8585
}
8686

87-
// --- todo_fail_void.carbon
87+
// --- fail_void.carbon
8888

8989
library "[[@TEST_NAME]]";
9090

9191
import Cpp inline "";
9292

93-
fn F(x: Cpp.void);
93+
// CHECK:STDERR: fail_void.carbon:[[@LINE+5]]:6: error: parameter has incomplete type `Cpp.void` in function definition [IncompleteTypeInFunctionParam]
94+
// CHECK:STDERR: fn F(x: Cpp.void) {}
95+
// CHECK:STDERR: ^~~~~~~~~~~
96+
// CHECK:STDERR: fail_void.carbon: note: `Cpp.void` is always-incomplete [CppVoidIncomplete]
97+
// CHECK:STDERR:
98+
fn F(x: Cpp.void) {}
9499

95100
// --- non_nullable_pointer.carbon
96101

toolchain/check/type_completion.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,7 @@ class TypeCompleter {
195195
auto BuildInfoForInst(SemIR::TypeId /*type_id*/,
196196
SemIR::CppVoidType /*inst*/) const
197197
-> SemIR::CompleteTypeInfo {
198-
// TODO: `CppVoidType` should be always-incomplete.
199-
return {.value_repr = MakeEmptyValueRepr()};
198+
CARBON_FATAL("`CppVoidType` is always-incomplete");
200199
}
201200

202201
auto BuildInfoForInst(SemIR::TypeId type_id,
@@ -372,6 +371,17 @@ auto TypeCompleter::AddNestedIncompleteTypes(SemIR::Inst type_inst) -> bool {
372371
Push(context_->types().GetTypeIdForTypeInstId(inst.inner_id));
373372
break;
374373
}
374+
case SemIR::CppVoidType::Kind: {
375+
// TODO: Consider checking `VoidTy` for completeness and checking whether
376+
// this extra check triggers an error. For that, reuse the code in
377+
// https://github.com/carbon-language/carbon-lang/blob/ca3f95faa610fdb9412c9e58ece524abf30c7a9e/toolchain/check/cpp/import.cpp#L2317-L2325.
378+
if (diagnoser_) {
379+
CARBON_DIAGNOSTIC(CppVoidIncomplete, Note,
380+
"`Cpp.void` is always-incomplete");
381+
diagnoser_().Note(SemIR::LocId::None, CppVoidIncomplete).Emit();
382+
}
383+
return false;
384+
}
375385
case CARBON_KIND(SemIR::CustomLayoutType inst): {
376386
for (auto field : context_->struct_type_fields().Get(inst.fields_id)) {
377387
Push(context_->types().GetTypeIdForTypeInstId(field.type_inst_id));

toolchain/diagnostics/diagnostic_kind.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ CARBON_DIAGNOSTIC_KIND(ClassForwardDeclaredHere)
289289
CARBON_DIAGNOSTIC_KIND(ClassSpecificDeclOutsideClass)
290290
CARBON_DIAGNOSTIC_KIND(ClassSpecificDeclPrevious)
291291
CARBON_DIAGNOSTIC_KIND(ClassIncompleteWithinDefinition)
292+
CARBON_DIAGNOSTIC_KIND(CppVoidIncomplete)
292293
CARBON_DIAGNOSTIC_KIND(GenericVirtual)
293294
CARBON_DIAGNOSTIC_KIND(OverrideWithoutBase)
294295
CARBON_DIAGNOSTIC_KIND(OverrideWithoutVirtualInBase)

0 commit comments

Comments
 (0)