@@ -1164,23 +1164,22 @@ void swift::conformToCxxSpanIfNeeded(ClangImporter::Implementation &impl,
11641164 if (!elementType || !sizeType)
11651165 return ;
11661166
1167- auto constPointerTypeDecl =
1168- lookupNestedClangTypeDecl (clangDecl, " const_pointer" );
1167+ auto pointerTypeDecl = lookupNestedClangTypeDecl (clangDecl, " pointer" );
11691168 auto countTypeDecl = lookupNestedClangTypeDecl (clangDecl, " size_type" );
11701169
1171- if (!constPointerTypeDecl || !countTypeDecl)
1170+ if (!pointerTypeDecl || !countTypeDecl)
11721171 return ;
11731172
1174- // create fake variable for constPointer (constructor arg 1)
1175- auto constPointerType = clangCtx.getTypeDeclType (constPointerTypeDecl );
1176- auto fakeConstPointerVarDecl = clang::VarDecl::Create (
1173+ // create fake variable for pointer (constructor arg 1)
1174+ clang::QualType pointerType = clangCtx.getTypeDeclType (pointerTypeDecl );
1175+ auto fakePointerVarDecl = clang::VarDecl::Create (
11771176 clangCtx, /* DC*/ clangCtx.getTranslationUnitDecl (),
11781177 clang::SourceLocation (), clang::SourceLocation (), /* Id*/ nullptr ,
1179- constPointerType , clangCtx.getTrivialTypeSourceInfo (constPointerType ),
1178+ pointerType , clangCtx.getTrivialTypeSourceInfo (pointerType ),
11801179 clang::StorageClass::SC_None);
11811180
1182- auto fakeConstPointer = new (clangCtx) clang::DeclRefExpr (
1183- clangCtx, fakeConstPointerVarDecl , false , constPointerType ,
1181+ auto fakePointer = new (clangCtx) clang::DeclRefExpr (
1182+ clangCtx, fakePointerVarDecl , false , pointerType ,
11841183 clang::ExprValueKind::VK_LValue, clang::SourceLocation ());
11851184
11861185 // create fake variable for count (constructor arg 2)
@@ -1197,8 +1196,7 @@ void swift::conformToCxxSpanIfNeeded(ClangImporter::Implementation &impl,
11971196
11981197 // Use clangSema.BuildCxxTypeConstructExpr to create a CXXTypeConstructExpr,
11991198 // passing constPointer and count
1200- SmallVector<clang::Expr *, 2 > constructExprArgs = {fakeConstPointer,
1201- fakeCount};
1199+ SmallVector<clang::Expr *, 2 > constructExprArgs = {fakePointer, fakeCount};
12021200
12031201 auto clangDeclTyInfo = clangCtx.getTrivialTypeSourceInfo (
12041202 clang::QualType (clangDecl->getTypeForDecl (), 0 ));
@@ -1226,5 +1224,10 @@ void swift::conformToCxxSpanIfNeeded(ClangImporter::Implementation &impl,
12261224 elementType->getUnderlyingType ());
12271225 impl.addSynthesizedTypealias (decl, ctx.getIdentifier (" Size" ),
12281226 sizeType->getUnderlyingType ());
1229- impl.addSynthesizedProtocolAttrs (decl, {KnownProtocolKind::CxxSpan});
1227+
1228+ if (pointerType->getPointeeType ().isConstQualified ()) {
1229+ impl.addSynthesizedProtocolAttrs (decl, {KnownProtocolKind::CxxSpan});
1230+ } else {
1231+ impl.addSynthesizedProtocolAttrs (decl, {KnownProtocolKind::CxxMutableSpan});
1232+ }
12301233}
0 commit comments