This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Restore `basic_ios`'s implicit conversion to `bool` in C++03 mode.
ClosedPublic

Authored by Quuxplusone on Aug 6 2021, 12:23 PM.

Details

Summary

@efriedma noted that my D104682 broke this test case, reduced from SPEC2006.

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

We can unbreak it by restoring the conversion to something-convertible-to-bool. I chose const void* to match libstdc++ (which uses non-const void*). We could of course just choose bool itself, but that would break some existing libc++ tests which assert basic_ios is NOT convertible to int.

I'm not at all sure that we want this patch; it might be better to say that in the year 2021 we no longer support a benchmark from 2006 written in a language from 2003, and those people should just fix their code already. But if we want it, then I think this is what we want. @efriedma, what are your thoughts re: the appropriate libc++ action here?

Diff Detail

Event Timeline

Quuxplusone requested review of this revision.Aug 6 2021, 12:23 PM
Quuxplusone created this revision.
Herald added 1 blocking reviewer(s): Restricted Project. · View Herald TranscriptAug 6 2021, 12:23 PM

This codepath is only used if someone is explicitly building with -std=c++98. If someone is explicitly requesting -std=c++98, they're presumably dealing with ancient code they can't update for some reason. The only downside I can think of is a minor risk of ODR violations if you mix -std=c++98 and -std=c++11 code.

And yes, SPEC2006 is still relevant for various companies.

libcxx/include/ios
614

The ancient standards actually specify operator void*, not operator const void*, but that probably doesn't matter.

ldionne accepted this revision.Aug 10 2021, 12:34 PM

LGTM with my suggested change applied. Let's also cherry-pick this onto release/13.x to avoid breaking people.

libcxx/include/ios
614

Yeah, let's make this operator void* to match the C++03 spec.

This revision is now accepted and ready to land.Aug 10 2021, 12:34 PM

@tstellar Is it fine to cherry-pick this bugfix onto release/13.x? If it bit @efriedma, it may bite other users, so I'd rather cherry-pick it if that's possible.

Convert to void* instead of const void*. (This requires casting away const.)
Poke buildkite to make sure this last change didn't break anything in the test suite.

Welp, obviously that broke the existing test that tests !std::is_convertible<std::istream&, void*>.
So I propose we change the test, on the theory that "match libstdc++'s behavior exactly" is more important than "match libc++'s old behavior in some but not all obscure corner cases" (which is what I was trying to achieve with operator const void* in the original version of this PR). @ldionne, does this still seem reasonable to you?

This revision was landed with ongoing or failed builds.Aug 11 2021, 10:39 AM
This revision was automatically updated to reflect the committed changes.

Welp, obviously that broke the existing test that tests !std::is_convertible<std::istream&, void*>.
So I propose we change the test, on the theory that "match libstdc++'s behavior exactly" is more important than "match libc++'s old behavior in some but not all obscure corner cases" (which is what I was trying to achieve with operator const void* in the original version of this PR). @ldionne, does this still seem reasonable to you?

Yes, that seems reasonable.