Skip to content

[cxx-interop] Fix test/Interop/Cxx/stdlib/use-std-string.swift #58637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5655,10 +5655,20 @@ ClangImporter::getCXXFunctionTemplateSpecialization(SubstitutionMap subst,
}

bool ClangImporter::isCXXMethodMutating(const clang::CXXMethodDecl *method) {
return isa<clang::CXXConstructorDecl>(method) || !method->isConst() ||
(method->getParent()->hasMutableFields() &&
!isAnnotatedWith(method, "nonmutating")) ||
isAnnotatedWith(method, "mutating");
if (isa<clang::CXXConstructorDecl>(method) || !method->isConst())
return true;
if (isAnnotatedWith(method, "mutating"))
return true;
if (method->getParent()->hasMutableFields()) {
if (isAnnotatedWith(method, "nonmutating"))
return false;
// FIXME(rdar://91961524): figure out a way to handle mutable fields
// without breaking classes from the C++ standard library (e.g.
// `std::string` which has a mutable member in old libstdc++ version used on
// CentOS 7)
return false;
}
return false;
}

bool ClangImporter::isAnnotatedWith(const clang::CXXMethodDecl *method,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

// CHECK: struct HasMutableProperty {
// CHECK: func annotatedNonMutating() -> Int32
// CHECK: mutating func noAnnotation() -> Int32
// TODO-CHECK: mutating func noAnnotation() -> Int32
// CHECK: mutating func contradictingAnnotations() -> Int32
// CHECK: func duplicateAnnotations() -> Int32
// CHECK: var a: Int32
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ let obj = HasConstMethodAnnotatedAsMutating(a: 42) // expected-note {{change 'le
let i = obj.annotatedMutating() // expected-error {{cannot use mutating member on immutable value: 'obj' is a 'let' constant}}

let objWMutableProperty = HasMutableProperty(a: 42, b: 21) // expected-note {{change 'let' to 'var' to make it mutable}}
// expected-note@-1 {{change 'let' to 'var' to make it mutable}}
// TODO-note@-1 {{change 'let' to 'var' to make it mutable}}

let _ = objWMutableProperty.annotatedNonMutating()
let _ = objWMutableProperty.noAnnotation() // expected-error {{cannot use mutating member on immutable value: 'objWMutableProperty' is a 'let' constant}}
let _ = objWMutableProperty.noAnnotation() // TODO-error {{cannot use mutating member on immutable value: 'objWMutableProperty' is a 'let' constant}}
let _ = objWMutableProperty.contradictingAnnotations() // expected-error {{cannot use mutating member on immutable value: 'objWMutableProperty' is a 'let' constant}}
let _ = objWMutableProperty.duplicateAnnotations()

Expand Down
2 changes: 0 additions & 2 deletions test/Interop/Cxx/stdlib/use-std-string.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// Enable this everywhere once we have a solution for modularizing other C++ stdlibs: rdar://87654514
// REQUIRES: OS=macosx || OS=linux-gnu

// REQUIRES: rdar92621793

import StdlibUnittest
import StdString
#if os(Linux)
Expand Down