Subject: Re: bug#28623: 27.0.50; lisp/progmodes/cc-engine.el incorrect indentation of C++14 curly-brace initializer list

From: Tadeus Prastowo <[email-masked]>
Date: Thu, 9 Nov 2017 10:27:55 +0100

On Wed, Nov 8, 2017 at 8:23 PM, Alan Mackenzie <[email-masked]> wrote:

[...]

> OK.  The essential characteristic of your new file is:
>
>    ({ {..}, ..., {...}}, { {..} .....
>                            ^
>    l                  L
>
> With the critical point marked, c-inside-bracelist-p had calculated a
> backward search limit at position L, which was insufficient for it to
> determine its brace list characteristic.
>
> I've corrected c-inside-bracelist-p such that it now uses position l as
> this limit.  I've also taken the opportunity to simplify it quite a bit.
> This now appears to work.
>
> So, thank you for taking the time to test this, and finding this further
> bug.

My pleasure.  And thank you very much for looking into this last
problem as well.

>  Could I ask you, please, to try the amended patch which I include
> below.  This should, again, apply cleanly to the emacs-26 branch, or
> master.  It is a patch "from scratch"; it is not an incremental patch on
> top of the last one.

Cool!  Your new patch produces the following now:
int main() {
  /* Indentation produced by your new patch */
  fn({
      {1, 2, 3},
      {3, 4, 5},
      {6, 7, 8},
    }, {
        {1, 3},
        {4, 5},
        {7, 8},
    });
  for (const auto &v : fn({
                           {3, 4, 5},
                           {6, 7, 8},
                           {9, 10, 11},
      }, {
          {1, 3},
          {4, 5},
          {7, 8},
      })) {
    for (const auto &a : v) {
      std::cout << a << '\n';
    }
  }
  /* End: Indentation produced by your new patch */
}

So, you solved the problem :)

>> Additionally, I would argue that compared to the one produced by my
>> patch demonstrated above, the following indentation would be even
>> better:
>>   for (const auto &v : fn({
>>         {3, 4, 5},
>>         {6, 7, 8},
>>         {9, 10, 11},
>>       }, {
>>           {1, 3},
>>           {4, 5},
>>           {7, 8},
>>       })) {
>>     for (const auto &a : v) {
>>       std::cout << a << '\n';
>>     }
>>   }
>> Please let me know what you think about that.
>
> I think I would agree with you.  This is probably fixable by configuring
> the CC Mode indentation engine, possibly by writing a Line-up function,
> but I can't say for sure without looking at it more closely.

I will have a look at it this weekend.

>> > If you have nothing against it, I intend to put your test file (or bits
>> > of it) into a new file in the CC Mode test suite.
>
>> Yes, that is okay.
>
> Thanks, I'll do that.

You are welcome.

And, just out of curiosity, in cc-engine, there is a long function
with many inline comments in the form of CASE xxx.  Why aren't those
refactored into individual functions?  Performance issue?

> --
> Alan Mackenzie (Nuremberg, Germany).

--
Best regards,
Tadeus