Subject: 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: Mon, 6 Nov 2017 23:46:26 +0100

Hi Alan!

On Sat, Nov 4, 2017 at 8:56 PM, Alan Mackenzie <[email-masked]> wrote:
> Hello, Tadeus.
>
> On Thu, Oct 12, 2017 at 13:38:56 +0200, Tadeus Prastowo wrote:
>> Hi Alan!
>
>> On Wed, Oct 11, 2017 at 10:32 PM, Alan Mackenzie <[email-masked]> wrote:
>> > Hello, Tadeus.
>
>> [...]
>
>> > I'm sorry is been a week without any communication from me.  The reason
>> > is I've run into problems with other related cases.  For example, in
>
>> > 1.    auto bad4 = f <3> (
>> > 2.                       {3, 4},
>
>> > L2 needs to be parsed as an arglist-intro and indented as shown.  It's
>> > actually being parsed as a brace-list-open with anchor point on "auto".
>
>> > What's confusing me is the confusion between a brace list being
>> > recognised by its context (which is what
>> > c-looking-at-or-maybe-in-bracelist mostly does) and by its content.  The
>> > {3, 4} above is a brace list by its content but not by its context.
>> > However, it's being wrongly recognised as a by-context brace list, hence
>> > is being parsed and indented wrongly.
>
>> > I'm not going to have much time to sort this out over the next week or
>> > two, so please bear with me.  I haven't forgotten about this.
>
>> Thanks for sharing the problem with me.  I will also look into the
>> matter during this weekend.  Hopefully I can come up with a good
>> solution :)

Sorry that I did not manage to spare the last three weekends to look
into the problem :(

> I think I've solved this, though it's been perhaps the most difficult bug
> in CC Mode for some years.  Each time I thought I'd nailed it, some
> awkward test case would misbehave.

Thank you very much for working on it.

> Anyhow, would you please try the patch below, which should apply cleanly
> to either the emacs-26 branch or master.  It is not finished; for example
> I've still got to amend several comments.  Nevertheless I think it's
> working.  I look forward to hearing of any problems which are still in
> this patch, or of a report that it seems to be working.

The patch applied to master cleanly.

Against the mwe.cpp I sent the other day, the patch works fine.  But,
it does not work with the following one:

-- 8< ----------------------------------
int main() {
  /* Indentation produced by my patch the other day */
  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 my patch the other day */

  /* Problem observed using your 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: Problem observed using your patch */
}
-- 8< ----------------------------------

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.

> 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.

[...]

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

--
Best regards,
Tadeus