From 2ad26487b6a1a8933b6b5be9cbd59a6da4220185 Mon Sep 17 00:00:00 2001 From: Boaz Brickner Date: Thu, 13 Nov 2025 21:53:03 +0100 Subject: [PATCH] C++ Interop: Don't crash when trying to call a C++ function with undeduced return type (#6363) This crashed on trying to build a C++ thunk because the error wasn't propagated. Part of #5436. --- toolchain/check/cpp/import.cpp | 3 +++ .../interop/cpp/function/return.carbon | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/toolchain/check/cpp/import.cpp b/toolchain/check/cpp/import.cpp index a2c06bcdb4aa..0a2a8a89ca50 100644 --- a/toolchain/check/cpp/import.cpp +++ b/toolchain/check/cpp/import.cpp @@ -1546,6 +1546,9 @@ static auto GetReturnPattern(Context& context, SemIR::LocId loc_id, // void. return SemIR::InstId::None; } + if (type_inst_id == SemIR::ErrorInst::TypeInstId) { + return SemIR::ErrorInst::InstId; + } auto pattern_type_id = GetPatternType(context, type_id); clang::SourceLocation return_type_loc = clang_decl->getReturnTypeSourceRange().getBegin(); diff --git a/toolchain/check/testdata/interop/cpp/function/return.carbon b/toolchain/check/testdata/interop/cpp/function/return.carbon index de70ef916347..c01773e4108f 100644 --- a/toolchain/check/testdata/interop/cpp/function/return.carbon +++ b/toolchain/check/testdata/interop/cpp/function/return.carbon @@ -35,6 +35,26 @@ fn F() { //@dump-sem-ir-end } +// ============================================================================ +// Undeduced return type +// ============================================================================ + +// --- fail_return_undeduced_auto.carbon + +library "[[@TEST_NAME]]"; + +import Cpp inline ''' +auto UndeducedReturn(); +'''; + +fn Call() { + // CHECK:STDERR: fail_return_undeduced_auto.carbon:[[@LINE+4]]:3: error: semantics TODO: `Unsupported: return type: auto` [SemanticsTodo] + // CHECK:STDERR: Cpp.UndeducedReturn(); + // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~ + // CHECK:STDERR: + Cpp.UndeducedReturn(); +} + // CHECK:STDOUT: --- import_multiple.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants {