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 {