Support for passing pointers to function templates. (#6080)

When a function template takes a parameter of deduced type, and we
deduce that type to a pointer type because we passed a Carbon pointer as
the argument, don't complain that the deduced type is not nullable. We
still know that it can't be null, because we deduced it from a
non-nullable type.
This commit is contained in:
Richard Smith authored and GitHub committed 2025-09-16 23:39:07 +00:00
1 parent b054e3d2b0
commit 9d84391f11
2 files changed
+228 -2

No files matched your search

+6 -2
View File
@@ -1255,8 +1255,12 @@ static auto MapPointerType(Context& context, clang::QualType type,
if (auto nullability = type->getNullability();
!nullability.has_value() ||
*nullability != clang::NullabilityKind::NonNull) {
// TODO: Support nullable pointers.
return TypeExpr::None;
// If the type was produced by C++ template substitution, then we assume it
// was deduced from a Carbon pointer type, so it's non-null.
if (!type->getAs<clang::SubstTemplateTypeParmType>()) {
// TODO: Support nullable pointers.
return TypeExpr::None;
}
}
SemIR::TypeId pointer_type_id =