This is an archive of the discontinued LLVM Phabricator instance.

Fix ostream for complex numbers with fixed field width
ClosedPublic

Authored by cantonios on Apr 24 2020, 9:40 AM.

Details

Summary

The ostream operator << is currently broken for std::complex with specified field widths.

For example,

const std::complex<float> x(10, 34);
std::cout << std::setfill('_') << std::setw(10) << x << std::endl;

should output

___(10,34)

for a total width of 10, but currently does:

_________(10,34)

for a total width of width-1+7 = 16.

This patch a partial reversion of c3478eff7a65d6a77b34e756eabc7176a2b422e8 (reviewed at https://reviews.llvm.org/D71214), restoring the correct behavior. Also added a test to libcxx/test/std/numerics/complex.number/complex.ops/stream_output.pass.cpp to catch this error in the future.

Tested:

$ llvm-lit libcxx/test/std/numerics/complex.number

Diff Detail

Event Timeline

cantonios created this revision.Apr 24 2020, 9:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 24 2020, 9:40 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
cantonios updated this revision to Diff 261260.Apr 30 2020, 9:24 AM

@cantonios, thanks for working on this. I'll let @ldionne or others review in detail, but I have two high-level notes:

Ugh, sorry I hadn't seen that before. The patch LGTM but I agree we should add a test -- @cantonios can you add one?

cantonios updated this revision to Diff 261353.Apr 30 2020, 2:10 PM
cantonios edited the summary of this revision. (Show Details)
cantonios set the repository for this revision to rG LLVM Github Monorepo.

Updated with test.

@cantonios, thanks for working on this. I'll let @ldionne or others review in detail, but I have two high-level notes:

Done.

Ugh, sorry I hadn't seen that before. The patch LGTM but I agree we should add a test -- @cantonios can you add one?

Done.

ldionne accepted this revision.Apr 30 2020, 2:33 PM
This revision is now accepted and ready to land.Apr 30 2020, 2:33 PM

Do you need help committing this? If so, please specify the Git information to commit under as "First Last <email@foo.com>". Thanks!

Yes, thanks, I don't have commit access.

"Antonio Sanchez <cantonios@google.com>"

Thanks! Committed as

commit aa0b991dcf0510793a42a5b01aaf06a6c0892bcf
Author: Antonio Sanchez <cantonios@google.com>
Date:   Thu May 7 13:49:12 2020 -0400

    [libc++] Fix ostream for complex numbers with fixed field width

    The ostream operator<< is currently broken for std::complex with
    specified field widths.

    This patch a partial revert of c3478eff7a65 (reviewed as D71214),
    restoring the correct behavior.

    Differential Revision: https://reviews.llvm.org/D78816
This revision was automatically updated to reflect the committed changes.