mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-01 22:02:45 +01:00
C++ interop: support for default arguments. (#6108)
The general strategy here is to force use of a thunk when we want to use default arguments, and have Clang generate uses of the default arguments on its side of the thunk. To support this, change the key type used in `clang_decls` from being just a `Decl*` to being a pair of `Decl*` and number of parameters in the case of function decls. Import distinct `SemIR::Function`s for each number of parameters that's used, and corresponding distinct thunks. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
co-authored by
Jon Ross-Perkins
parent
82679e6689
commit
1e7b7e53ae
@@ -10,6 +10,7 @@
|
||||
#include "toolchain/check/cpp/import.h"
|
||||
#include "toolchain/check/cpp/location.h"
|
||||
#include "toolchain/check/cpp/type_mapping.h"
|
||||
#include "toolchain/diagnostics/diagnostic_emitter.h"
|
||||
#include "toolchain/sem_ir/ids.h"
|
||||
#include "toolchain/sem_ir/typed_insts.h"
|
||||
|
||||
@@ -79,6 +80,12 @@ auto PerformCppOverloadResolution(Context& context, SemIR::LocId loc_id,
|
||||
SemIR::InstId self_id,
|
||||
llvm::ArrayRef<SemIR::InstId> arg_ids)
|
||||
-> SemIR::InstId {
|
||||
// Register an annotation scope to flush any Clang diagnostics when we return.
|
||||
// This is important to ensure that Clang diagnostics are properly interleaved
|
||||
// with Carbon diagnostics.
|
||||
Diagnostics::AnnotationScope annotate_diagnostics(&context.emitter(),
|
||||
[](auto& /*builder*/) {});
|
||||
|
||||
// Map Carbon call argument types to C++ types.
|
||||
clang::Expr* self_expr = nullptr;
|
||||
if (self_id.has_value()) {
|
||||
@@ -117,8 +124,8 @@ auto PerformCppOverloadResolution(Context& context, SemIR::LocId loc_id,
|
||||
// TODO: Handle the cases when Function is null.
|
||||
CARBON_CHECK(best_viable_fn->Function);
|
||||
sema.MarkFunctionReferenced(loc, best_viable_fn->Function);
|
||||
SemIR::InstId result =
|
||||
ImportCppFunctionDecl(context, loc_id, best_viable_fn->Function);
|
||||
SemIR::InstId result = ImportCppFunctionDecl(
|
||||
context, loc_id, best_viable_fn->Function, arg_exprs.size());
|
||||
return result;
|
||||
}
|
||||
case clang::OverloadingResult::OR_No_Viable_Function: {
|
||||
|
||||
Reference in New Issue
Block a user