Skip to content
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

Inconsistent print() behaviour with std.string #76520

Open
Drejzer opened this issue Sep 17, 2024 · 0 comments
Open

Inconsistent print() behaviour with std.string #76520

Drejzer opened this issue Sep 17, 2024 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@Drejzer
Copy link

Drejzer commented Sep 17, 2024

Description

Printing strings from a c++ object in swift I was receiving only in the output

basic_string<CChar, char_traits<CChar>, allocator<CChar>>()

which was a drastic change from Swift 5.10, where I would receive
std.__1.string("contents of the string")

initialising a variable (var t :std.string = "test") causes print to output the strings themselves,
as in printing contents of the string

Reproduction

Make a package using swift-tools 6.0

in cpp target:

namespace stringtest{
class test{
public:
	std::string sauce="";
	int64_t id;
	std::string type="";
	virtual void kek(){};
};

class derivedTest1 : public test{
public:
	//derivedTest1() : test::test(){data = "testing now";};
	std::string data;
	void kek() override{}
	const std::string& getSauce() const {
		return sauce;
	}
};

static derivedTest1 minTest(){
	derivedTest1 x;
	x.data = "abcdefghijklmno11111112";
	x.sauce = "abcdefghijklmno11111112";
	x.id = int64_t(&x);
	x.type = "derivedTest1";
	return x;
}
}

then in an executable target import cpp one and:

let res = stringtest.minTest()
print(res.id)
print(res.data)
print(res.type)
print(res.__getSauceUnsafe().pointee)
print(res.sauce)
//var t1 : std.string = "test"

uncomment the last line and run again.

Expected behavior

Either 5.10 behaviour, or at least a consistent behaviour overall.

Environment

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx14.0

Additional information

No response

@Drejzer Drejzer added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant