[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#19867: c++-mode indentation issues with C++1x initializer lists

From: Stefan Kangas
Subject: bug#19867: c++-mode indentation issues with C++1x initializer lists
Date: Mon, 23 Nov 2020 09:14:43 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Simon <turner25@gmail.com> writes:

> Initializer lists use curly braces, but their contents do not indent properly 
> with emacs' c++-mode.
> In short, one may use an initializer list to declare and initialize a vector 
> of integers as such:
>   std::vector<int> Foo( { 1, 2, 3, 4, 5 } );
> Problems arise when the elements of the list span on multiple line and it 
> gets even worse when the elements are lambda-expressions
> and nested initializer lists.
> The following code illustrate most cases and related situations.  The code 
> below compiles without error or warning with gcc 4.8.3.

I had a look at the fairly long example provided here, and AFAICT, the
indentation is incorrect in the below cases (trimmed down from the
original).  Some of the examples of incorrect indentation were already

Alan, could you perhaps take a look at this and see if this is something
that is fixable?  Thanks in advance.

#include <vector>
#include <functional>

namespace emacs_initlist_indentation_bug {
  struct DEF {
    int d, //
      e,   // indented from "int" + 2
      f;   //
  struct GHI {
    int   //
    g,    // indented from "int" +0
      h,  // indented from "int" + 2
      i;  //

  void f4 (int a, int b, int c)
    std::vector<ABC> abcList2(                     // Source of
alignment for closing ")" below
      }                    //
                                                   ); /* Somehow, this
one aligns with first line's comment position!! */

  lambda_initlist_bug.push_back(              //
    [](int p)     // OK, text-book indentation
    {             //
      return p+p; //
    }             //
                                              );  /* Aligned with
first comment! */

reply via email to

[Prev in Thread] Current Thread [Next in Thread]