Port endl to std::cout/std::cerr or "\n" + flush when necessary. In qt5.15 endl is namespaced.
AbandonedPublic

Authored by mlaurent on Jan 5 2020, 12:48 PM.

Details

Reviewers
dfaure
tcanabrava
Summary

Port endl as in qt5.15 it's namespaced

Diff Detail

Repository
R237 KConfig
Branch
port_endl (branched from master)
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 20640
Build 20658: arc lint + arc unit
mlaurent created this revision.Jan 5 2020, 12:48 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptJan 5 2020, 12:48 PM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
mlaurent requested review of this revision.Jan 5 2020, 12:48 PM
anthonyfieroni added inline comments.
autotests/kconfigtest.cpp
533–542

When it has only strings you can use R"()"
https://en.cppreference.com/w/cpp/language/string_literal

dfaure requested changes to this revision.Jan 5 2020, 6:26 PM
dfaure added a reviewer: tcanabrava.

Oh boy this is going to really give a big conflict with D26202!

Given that this commit is "more trivial" than D26202, maybe it should happen again *after* D26202 lands...

autotests/kconfigtest.cpp
533–542

What would be the benefit here? One double-backslash simplified to a single one, and that's it, right?

src/kconfig_compiler/kconfig_compiler.cpp
694

Why? Surely the QTextStream destructor (which is called here) will take care of that.

729

(same)

881

(pre-existing) Strange that this one is cout and not cerr...

1379

I've been wondering if this flush() is needed.

In my tests, it works without. http://www.davidfaure.fr/2020/qtextstream_flush.cpp
QTextStream is notified of the QString being deleted, and flushes.

But in theory local variables are deleted *after* the return value is copied (otherwise mutex lockers wouldn't make sense, stack overflow confirms) so in the absence of named-return-value-optimization (which IIRC is only guaranteed in C++17 and later), the copying could happen before the flushing.

Unless I missed something, let's keep the flush() to be safe :-)

This revision now requires changes to proceed.Jan 5 2020, 6:26 PM
mlaurent added inline comments.Jan 6 2020, 5:50 AM
src/kconfig_compiler/kconfig_compiler.cpp
694

I think that it was a problem when QTextStream used QString which doesn't flush it.
code is a QString

dfaure added inline comments.Jan 6 2020, 11:08 PM
src/kconfig_compiler/kconfig_compiler.cpp
694

I think you're confusing two cases.

The "underlying device" goes away before the QTextStream ==> this only works when the device is a proper QIODevice, while a QString has no "closed notification".

The QTextStream goes away before the underlying device. No problem in either case, the QTextStream destructor flushes.