Adds support for exporting default values for concrete parameters of generic functions. (#8019)

Adds support for exporting both the generic function decl with concrete
default arguments to clang, as well as exporting the monomorphized
concrete function def.

This required adding the `SpecificId` to the exported global variable
name, to avoid duplicate names in the global vars. I also now set up an
evaluated context in `clang_sema` when declaring the default arg
expression with clang, to avoid the problem of emitting concrete AST
expressions in an unevaluated context from the in-progress template
function decl context when exporting default values for generics.

Note: Default values for generic parameters of generic functions are not
yet supported.
This commit is contained in:
Lucile Rose Nihlen authored and GitHub committed 2026-10-26 16:21:41 +00:00
1 parent 21c825a3f7
commit c7de727575
2 files changed
+192 -119

No files matched your search

@@ -10,6 +10,32 @@
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/function/export/default_values.carbon
// --- generic_fn_concrete_default.carbon
library "[[@TEST_NAME]]";
import Cpp;
interface Z {};
class D { adapt {}; }
impl D as Z {}
fn MakeD() -> D { return {} as D; }
class E { adapt {}; }
class C(T: Z) {
var e: E;
}
fn Make[T: Z](unused t: T, e: E = {} as E) -> C(T) {
return {.e = e} as C(T);
}
inline Cpp '''
void CallMake() {
Carbon::Make(Carbon::MakeD());
}
''';
// --- other.carbon
library "[[@TEST_NAME]]";