Repository: carbon-language/carbon-lang
File: toolchain/check/cpp/import.cpp (C++)

Code before:
  if (!type_id.has_value()) {
    context.TODO(
        loc_id, "Unsupported: constant type: " + expr->getType().getAsString());
    return SemIR::ErrorInst::InstId;
  }

  SemIR::InstId inst_id = SemIR::InstId::None;
  SemIR::ImportIRInstId imported_loc_id =
      AddImportIRInst(context.sem_ir(), expr->getExprLoc());

  if (auto* integer_literal = dyn_cast<clang::IntegerLiteral>(expr)) {
    IntId int_id =
        context.ints().Add(integer_literal->getValue().getSExtValue());
    inst_id = AddInstInNoBlock(
        context,
        MakeImportedLocIdAndInst<SemIR::IntValue>(
            context, imported_loc_id, {.type_id = type_id, .int_id = int_id}));
  } else if (auto* float_literal = dyn_cast<clang::FloatingLiteral>(expr)) {
    FloatId float_id = context.floats().Add(float_literal->getValue());
    inst_id = AddInstInNoBlock(context,
                               MakeImportedLocIdAndInst<SemIR::FloatValue>(
                                   context, imported_loc_id,
                                   {.type_id = type_id, .float_id = float_id}));
  } else {
    context.TODO(
        loc_id, "Unsupported: constant type: " + expr->getType().getAsString());
    return SemIR::ErrorInst::InstId;
  }

  context.imports().push_back(inst_id);
  return inst_id;
}

// Imports a macro definition into the scope. Currently supports only simple
// object-like macros that expand to a constant integer value.
// TODO: Add support for other macro types and non-integer literal values.
static auto ImportMacro(Context& context, SemIR::LocId loc_id,
                        SemIR::NameScopeId scope_id, SemIR::NameId name_id,
                        clang::MacroInfo* macro_info)
    -> SemIR::ScopeLookupResult {
  clang::Expr* macro_expr =
      TryEvaluateMacroToConstant(context, loc_id, name_id, macro_info);

  if (!macro_expr) {
    return SemIR::ScopeLookupResult::MakeNotFound();
  }

  auto inst_id = MapConstant(context, loc_id, macro_expr);
  if (inst_id == SemIR::ErrorInst::InstId) {
    return SemIR::ScopeLookupResult::MakeNotFound();
  }

Review comment (suggestion):
One more comment; had you considered varying the TODO messages, just to make it easier to see which code path was being hit? Right now you have pretty much the same message on lines 2239 and 2262 here, plus macros.cpp.

Code after:
  if (!type_id.has_value()) {
    context.TODO(loc_id, llvm::formatv("Unsupported: C++ literal's type `{0}` "
                                       "could not be mapped to a Carbon type",
                                       expr->getType().getAsString()));
    return SemIR::ErrorInst::InstId;
  }

  SemIR::InstId inst_id = SemIR::InstId::None;
  SemIR::ImportIRInstId imported_loc_id =
      AddImportIRInst(context.sem_ir(), expr->getExprLoc());

  if (auto* integer_literal = dyn_cast<clang::IntegerLiteral>(expr)) {
    IntId int_id =
        context.ints().Add(integer_literal->getValue().getSExtValue());
    inst_id = AddInstInNoBlock(
        context,
        MakeImportedLocIdAndInst<SemIR::IntValue>(
            context, imported_loc_id, {.type_id = type_id, .int_id = int_id}));
  } else if (auto* float_literal = dyn_cast<clang::FloatingLiteral>(expr)) {
    FloatId float_id = context.floats().Add(float_literal->getValue());
    inst_id = AddInstInNoBlock(context,
                               MakeImportedLocIdAndInst<SemIR::FloatValue>(
                                   context, imported_loc_id,
                                   {.type_id = type_id, .float_id = float_id}));
  } else {
    context.TODO(loc_id, llvm::formatv(
                             "Unsupported: C++ constant expression type: '{0}'",
                             expr->getType().getAsString()));
    return SemIR::ErrorInst::InstId;
  }

  context.imports().push_back(inst_id);
  return inst_id;
}

// Imports a macro definition into the scope. Currently supports only simple
// object-like macros that expand to a constant integer value.
// TODO: Add support for other macro types and non-integer literal values.
static auto ImportMacro(Context& context, SemIR::LocId loc_id,
                        SemIR::NameScopeId scope_id, SemIR::NameId name_id,
                        clang::MacroInfo* macro_info)
    -> SemIR::ScopeLookupResult {
  clang::Expr* macro_expr =
      TryEvaluateMacroToConstant(context, loc_id, name_id, macro_info);

  if (!macro_expr) {
    return SemIR::ScopeLookupResult::MakeNotFound();
  }

  auto inst_id = MapConstant(context, loc_id, macro_expr);
  if (inst_id == SemIR::ErrorInst::InstId) {