@@ -2086,18 +2086,22 @@ ImportedType ClangImporter::Implementation::importFunctionReturnType(
20862086 OptionalityOfReturn = OTK_ImplicitlyUnwrappedOptional;
20872087 }
20882088
2089+ clang::QualType returnType = clangDecl->getReturnType ();
2090+ if (auto elaborated =
2091+ dyn_cast<clang::ElaboratedType>(returnType))
2092+ returnType = elaborated->desugar ();
2093+
20892094 // Specialized templates need to match the args/result exactly (i.e.,
20902095 // ptr -> ptr not ptr -> Optional<ptr>).
2091- if (clangDecl->getReturnType ()->isPointerType () &&
2092- clangDecl->getPrimaryTemplate () &&
2096+ if (returnType->isPointerType () && clangDecl->getPrimaryTemplate () &&
20932097 clangDecl
20942098 ->getPrimaryTemplate ()
20952099 ->getAsFunction ()
20962100 ->getReturnType ()
20972101 ->isTemplateTypeParmType ())
20982102 OptionalityOfReturn = OTK_None;
20992103
2100- if (auto typedefType = dyn_cast<clang::TypedefType>(clangDecl-> getReturnType (). getTypePtr () )) {
2104+ if (auto typedefType = dyn_cast<clang::TypedefType>(returnType )) {
21012105 if (isUnavailableInSwift (typedefType->getDecl ())) {
21022106 if (auto clangEnum = findAnonymousEnumForTypedef (SwiftContext, typedefType)) {
21032107 // If this fails, it means that we need a stronger predicate for
@@ -2112,7 +2116,7 @@ ImportedType ClangImporter::Implementation::importFunctionReturnType(
21122116 }
21132117
21142118 // Import the result type.
2115- return importType (clangDecl-> getReturnType () ,
2119+ return importType (returnType ,
21162120 (isAuditedResult ? ImportTypeKind::AuditedResult
21172121 : ImportTypeKind::Result),
21182122 ImportDiagnosticAdder (*this , clangDecl,
@@ -2159,7 +2163,11 @@ ImportedType ClangImporter::Implementation::importFunctionParamsAndReturnType(
21592163 ImportedType importedType;
21602164 ImportDiagnosticAdder addDiag (*this , clangDecl,
21612165 clangDecl->getSourceRange ().getBegin ());
2162- if (auto typedefType = dyn_cast<clang::TypedefType>(clangDecl->getReturnType ().getTypePtr ())) {
2166+ clang::QualType returnType = clangDecl->getReturnType ();
2167+ if (auto elaborated = dyn_cast<clang::ElaboratedType>(returnType))
2168+ returnType = elaborated->desugar ();
2169+
2170+ if (auto typedefType = dyn_cast<clang::TypedefType>(returnType)) {
21632171 if (isUnavailableInSwift (typedefType->getDecl ())) {
21642172 if (auto clangEnum = findAnonymousEnumForTypedef (SwiftContext, typedefType)) {
21652173 // If this fails, it means that we need a stronger predicate for
@@ -2174,15 +2182,15 @@ ImportedType ClangImporter::Implementation::importFunctionParamsAndReturnType(
21742182 }
21752183
21762184 if (auto templateType =
2177- dyn_cast<clang::TemplateTypeParmType>(clangDecl-> getReturnType () )) {
2185+ dyn_cast<clang::TemplateTypeParmType>(returnType )) {
21782186 importedType = {findGenericTypeInGenericDecls (
21792187 *this , templateType, genericParams,
21802188 getImportTypeAttrs (clangDecl), addDiag),
21812189 false };
2182- } else if ((isa<clang::PointerType>(clangDecl-> getReturnType () ) ||
2183- isa<clang::ReferenceType>(clangDecl-> getReturnType () )) &&
2184- isa<clang::TemplateTypeParmType>(clangDecl-> getReturnType () ->getPointeeType ())) {
2185- auto pointeeType = clangDecl-> getReturnType () ->getPointeeType ();
2190+ } else if ((isa<clang::PointerType>(returnType ) ||
2191+ isa<clang::ReferenceType>(returnType )) &&
2192+ isa<clang::TemplateTypeParmType>(returnType ->getPointeeType ())) {
2193+ auto pointeeType = returnType ->getPointeeType ();
21862194 auto templateParamType = cast<clang::TemplateTypeParmType>(pointeeType);
21872195 PointerTypeKind pointerKind = pointeeType.getQualifiers ().hasConst ()
21882196 ? PTK_UnsafePointer
@@ -2191,13 +2199,13 @@ ImportedType ClangImporter::Implementation::importFunctionParamsAndReturnType(
21912199 findGenericTypeInGenericDecls (*this , templateParamType, genericParams,
21922200 getImportTypeAttrs (clangDecl), addDiag);
21932201 importedType = {genericType->wrapInPointer (pointerKind), false };
2194- } else if (!(isa<clang::RecordType>(clangDecl-> getReturnType () ) ||
2195- isa<clang::TemplateSpecializationType>(clangDecl-> getReturnType () )) ||
2202+ } else if (!(isa<clang::RecordType>(returnType ) ||
2203+ isa<clang::TemplateSpecializationType>(returnType )) ||
21962204 // TODO: we currently don't lazily load operator return types, but
21972205 // this should be trivial to add.
21982206 clangDecl->isOverloadedOperator () ||
21992207 // Dependant types are trivially mapped as Any.
2200- clangDecl-> getReturnType () ->isDependentType ()) {
2208+ returnType ->isDependentType ()) {
22012209 // If importedType is already initialized, it means we found the enum that
22022210 // was supposed to be used (instead of the typedef type).
22032211 if (!importedType) {
@@ -2244,6 +2252,8 @@ ClangImporter::Implementation::importParameterType(
22442252 ArrayRef<GenericTypeParamDecl *> genericParams,
22452253 llvm::function_ref<void (Diagnostic &&)> addImportDiagnosticFn) {
22462254 auto paramTy = param->getType ();
2255+ if (auto elaborated = dyn_cast<clang::ElaboratedType>(paramTy))
2256+ paramTy = elaborated->desugar ();
22472257
22482258 ImportTypeKind importKind = getImportTypeKindForParam (param);
22492259
@@ -2845,7 +2855,8 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
28452855 ImportDiagnosticAdder addImportDiag (*this , clangDecl,
28462856 clangDecl->getLocation ());
28472857 clang::QualType resultType = clangDecl->getReturnType ();
2848-
2858+ if (auto elaborated = dyn_cast<clang::ElaboratedType>(resultType))
2859+ resultType = elaborated->desugar ();
28492860
28502861 ImportedType importedType;
28512862 if (auto typedefType = dyn_cast<clang::TypedefType>(resultType.getTypePtr ())) {
0 commit comments