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

Code before:
        // TODO: Consider allowing setting `DiagnosticOptions` or use
        // `ASTUnit::getDiagnostics().::getLangOptions().getDiagnosticOptions()`.
        new clang::DiagnosticOptions());
    text_diagnostic.emitDiagnostic(
        clang::FullSourceLoc(info.getLocation(), info.getSourceManager()),
        diag_level, message, info.getRanges(), info.getFixItHints());

    std::string diagnostics_str = diagnostics_stream.TakeStr();

    switch (diag_level) {
      case clang::DiagnosticsEngine::Ignored:
      case clang::DiagnosticsEngine::Note:
      case clang::DiagnosticsEngine::Remark: {
        context_.TODO(
            loc_, llvm::formatv(
                      "Unsupported: C++ diagnostic level for diagnostic\n{0}",
                      diagnostics_str));
        return;
      }
      case clang::DiagnosticsEngine::Warning:
      case clang::DiagnosticsEngine::Error:
      case clang::DiagnosticsEngine::Fatal: {
        CARBON_DIAGNOSTIC(CppInteropParseWarning, Warning, "C++:\n{0}",
                          std::string);
        CARBON_DIAGNOSTIC(CppInteropParseError, Error, "C++:\n{0}",
                          std::string);
        CARBON_DIAGNOSTIC(InCppImport, Note, "in `Cpp` import");

        // TODO: Use a more specific location.
        context_.emitter()
            .Build(SemIR::LocId::None,
                   diag_level == clang::DiagnosticsEngine::Warning
                       ? CppInteropParseWarning
                       : CppInteropParseError,
                   diagnostics_str)
            .Note(loc_, InCppImport)
            .Emit();
        return;
      }
    }
  }

 private:
  // The type-checking context in which we're running Clang.
  Context& context_;

  // The location that triggered calling Clang.
  SemIRLoc loc_;
};

}  // namespace

Review comment (suggestion):
```suggestion
        // TODO: Adjust diagnostics to drop the Carbon file here, and then remove the "C++:\n" prefix.
        CARBON_DIAGNOSTIC(CppInteropParseWarning, Warning, "C++:\n{0}",
```

Code after:
        clang::LangOptions(),
        // TODO: Consider allowing setting `DiagnosticOptions` or use
        // `ASTUnit::getDiagnostics().::getLangOptions().getDiagnosticOptions()`.
        new clang::DiagnosticOptions());
    text_diagnostic.emitDiagnostic(
        clang::FullSourceLoc(info.getLocation(), info.getSourceManager()),
        diag_level, message, info.getRanges(), info.getFixItHints());

    std::string diagnostics_str = diagnostics_stream.TakeStr();

    switch (diag_level) {
      case clang::DiagnosticsEngine::Ignored:
      case clang::DiagnosticsEngine::Note:
      case clang::DiagnosticsEngine::Remark: {
        context_->TODO(
            loc_, llvm::formatv(
                      "Unsupported: C++ diagnostic level for diagnostic\n{0}",
                      diagnostics_str));
        return;
      }
      case clang::DiagnosticsEngine::Warning:
      case clang::DiagnosticsEngine::Error:
      case clang::DiagnosticsEngine::Fatal: {
        // TODO: Adjust diagnostics to drop the Carbon file here, and then
        // remove the "C++:\n" prefix.
        CARBON_DIAGNOSTIC(CppInteropParseWarning, Warning, "C++:\n{0}",
                          std::string);
        CARBON_DIAGNOSTIC(CppInteropParseError, Error, "C++:\n{0}",
                          std::string);
        // TODO: This should be part of the location, instead of added as a note
        // here.
        CARBON_DIAGNOSTIC(InCppImport, Note, "in `Cpp` import");

        // TODO: Use a more specific location.
        context_->emitter()
            .Build(SemIR::LocId::None,
                   diag_level == clang::DiagnosticsEngine::Warning
                       ? CppInteropParseWarning
                       : CppInteropParseError,
                   diagnostics_str)
            .Note(loc_, InCppImport)
            .Emit();
        return;
      }
    }
  }

 private:
  // The type-checking context in which we're running Clang.
  Context* context_;