This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Enable `explicit` conversion operators, even in C++03 mode.
ClosedPublic

Authored by Quuxplusone on Jun 21 2021, 7:32 PM.

Details

Summary

This is a "pivot" of the third part of D104310: instead of doing all of iostreams at once, let's do everyone's explicit conversion operators at once!

C++03 didn't support `explicit` conversion operators;
but Clang's C++03 mode does, as an extension, so we can use it.
This lets us make the conversion explicit in `std::function` (even in '03),
and remove some silly metaprogramming in `std::basic_ios`.

Drive-by improvements to the tests for these operators, in addition
to making sure all these tests also run in `c++03` mode.

Diff Detail

Event Timeline

Quuxplusone requested review of this revision.Jun 21 2021, 7:32 PM
Quuxplusone created this revision.
Herald added 1 blocking reviewer(s): Restricted Project. · View Herald TranscriptJun 21 2021, 7:32 PM
ldionne requested changes to this revision.Jun 22 2021, 9:12 AM

So the logic here is that we're not adding // UNSUPPORTED: c++03 to those tests even though they technically require C++11 (since we're testing stuff like std::shared_ptr, which was added in C++11), because libc++ implements those types as an extension?

I think it would be more logical to use // UNSUPPORTED: c++03 && !libc++. That way, other standard libraries that do not support those types in C++03 mode will not fail the test suite. WDYT?

Other than that, I'm fine with the changes and I like that we're removing workarounds for missing C++03 language features.

This revision now requires changes to proceed.Jun 22 2021, 9:12 AM
ldionne accepted this revision.Jun 22 2021, 10:09 AM

I just read https://reviews.llvm.org/D104172#2830696.

I think we need to figure out what to do with C++03 in the test suite (you accurately explained the state of things in https://reviews.llvm.org/D104172#2830696, but that state of things is not what it should be IMO). However, this patch is orthogonal to figuring that out, so I'm fine with it. Thanks a lot for the clean up!

libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/op_bool.pass.cpp
13

Thanks for that.

This revision is now accepted and ready to land.Jun 22 2021, 10:09 AM

This apparently broke compiling the following testcase, reduced from SPEC2006, in c++98 mode:

#include <istream>
bool a(std::istream a) {
    return a.getline(0,0) == 0;
}
libcxx/include/system_error