Reproducible with uncrustify 0.60 and 36a0f44c54e, using the following example code:
int main() { std::ostringstream oss; oss << "Line " << "is" << "very" << "long" << "and" << "continued" << "on" << "the" << "next" << "line" << "but" << "the" << "next" << "line" << "is" << "not" << "indeted" << "as" << "expected"; oss << "However," << "a" << "long" << "line" << "which" << "is" << "already" << "wrapped" << "and" << "has" << "a" << "stream" << "operator" << "at" << "the" << "beginning" << "is" << "apparently" << "aligned" << "as" << "expected."; std::string str = "This" + "line" + "is" + "also" + "very" + "long" + "and" + "continued" + "in" + "the" + "next" + "line," + "however" + "it" + "is" + "indented" + "as" + "expected"; }
With a configuration of:
indent_columns = 4 indent_continue = 12 code_width = 100 align_left_shift = true
the result is:
int main() { std::ostringstream oss; oss << "Line " << "is" << "very" << "long" << "and" << "continued" << "on" << "the" << "next" << "line" << "but" << "the" << "next" << "line" << "is" << "not" << "indeted" << "as" << "expected"; oss << "However," << "a" << "long" << "line" << "which" << "is" << "already" << "wrapped" << "and" << "has" << "a" << "stream" << "operator" << "at" << "the" << "beginning" << "is" << "apparently" << "aligned" << "as" << "expected."; std::string str = "This" + "line" + "is" + "also" + "very" + "long" + "and" + "continued" + "in" + "the" + "next" + "line," + "however" + "it" + "is" + "indented" + "as" + "expected"; }
Here uncrustify does not wrap before the "<<", making
align_left_shift useless. It only aligns lines which were wrapped manually at the right places
before.
Using
indent_columns = 4 indent_continue = 12 indent_with_tabs = 0 code_width = 100 align_left_shift = false
the result is
int main() { std::ostringstream oss; oss << "Line " << "is" << "very" << "long" << "and" << "continued" << "on" << "the" << "next" << "line" << "but" << "the" << "next" << "line" << "is" << "not" << "indeted" << "as" << "expected"; oss << "However," << "a" << "long" << "line" << "which" << "is" << "already" << "wrapped" << "and" << "has" << "a" << "stream" << "operator" << "at" << "the" << "beginning" << "is" << "apparently" << "aligned" << "as" << "expected."; std::string str = "This" + "line" + "is" + "also" + "very" + "long" + "and" + "continued" + "in" + "the" + "next" + "line," + "however" + "it" + "is" + "indented" + "as" + "expected"; }
Here I would actually expect the indent_continue setting to take effect (as it does on the + line and
also on the first example), however, no indentation is done for the continued stream line.
Something such as:
nl_before_left_shift = true
would produces:
oss << "However,"
<< "a"
<< "long"
<< "line"
<< "which"
<< "is"
<< "already"
<< "wrapped"
<< "and"
<< "has"
<< "a"
<< "stream"
<< "operator"
<< "at"
<< "the"
<< "beginning"
<< "is"
<< "apparently"
<< "aligned"
<< "as"
<< "expected.";
which is not pretty at all.
Please make any proposal!
It is not about wrapping before every << operator.
The point rather is that if wrapping is necessary, wrapping is not done at the location providing the most elegant result.
Maybe an option would be that if wrapping would leave a << operator at the end of the line, if align_left_shift
is given, rather wrap before that operator.
Desired result using align_left_shift = true:
What do you think about an option
wrapping_before_operator = true/false
which gives you a choose.
We have migrated the bug to:
https://github.com/uncrustify/uncrustify/issues/676