This is an archive of the discontinued LLVM Phabricator instance.

[libc++][tests] Fix a test exercising incorrect overload
ClosedPublic

Authored by pfusik on Jul 5 2023, 2:59 AM.

Details

Reviewers
ldionne
Group Reviewers
Restricted Project
Commits
rG1406f099de94: [libc++][tests] Fix a test exercising incorrect overload

Diff Detail

Event Timeline

pfusik created this revision.Jul 5 2023, 2:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 5 2023, 2:59 AM
pfusik requested review of this revision.Jul 5 2023, 2:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 5 2023, 2:59 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
pfusik added a comment.Jul 5 2023, 3:00 AM

I noticed a test I added in https://reviews.llvm.org/D153709 wasn't testing the constructor overload it was supposed to test. Instead, it tested the same overload as string-alloc.mode.pass.cpp.

ldionne requested changes to this revision.Jul 5 2023, 5:45 AM
ldionne added a subscriber: ldionne.

I noticed a test I added in https://reviews.llvm.org/D153709 wasn't testing the constructor overload it was supposed to test. Instead, it tested the same overload as string-alloc.mode.pass.cpp.

I don't think that's true. The test was exercising this constructor: explicit basic_stringbuf(basic_string<charT, traits, Allocator>&& s, ios_base::openmode which = ios_base::in | ios_base::out) unless I missed something subtle. We're specifying a test allocator in the type of basic_stringbuf, but we're not passing any allocator to the constructor itself. Did I miss something?

This revision now requires changes to proceed.Jul 5 2023, 5:45 AM
pfusik added a comment.Jul 5 2023, 5:54 AM

@ldionne std::basic_string<CharT, std::traits<CharT>, test_allocator<CharT>> is a different type than std::basic_string<CharT>.
I double-checked with printfs which constructor was called.

@ldionne Can we please continue this review before the 17.0 branch is created?

The constructor to be tested is not a template and the allocator of the moved string must be the same type as stringbuf's allocator.
It was not: the string had a default std::allocator while stringbuf had test_allocator.
A different overload was selected that allows a different allocator and we have a different test for it.

ldionne added inline comments.Aug 10 2023, 12:27 PM
libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string.move.mode.pass.cpp
29–36

OH!! I see it now. Okay, thanks for the fix.

What would you think about testing this thought?

std::basic_string<CharT, std::char_traits<CharT>, test_allocator<CharT>> s(STR("testing"));
const std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> buf(std::move(s));
assert(buf.str() == STR("testing"));

It's nice to use the test_allocator and not just the default one.

ldionne accepted this revision.Aug 10 2023, 12:27 PM

LGTM w/ suggestion and green CI

This revision is now accepted and ready to land.Aug 10 2023, 12:27 PM
pfusik updated this revision to Diff 549144.Aug 10 2023, 12:41 PM

Rebased. Added testing with test_allocator.

pfusik marked an inline comment as done.Aug 10 2023, 12:42 PM
This revision was landed with ongoing or failed builds.Aug 10 2023, 9:12 PM
This revision was automatically updated to reflect the committed changes.