https://bugs.llvm.org/show_bug.cgi?id=36460

            Bug ID: 36460
           Summary: trailing comma in inializer list confuses formatter
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Formatter
          Assignee: unassignedclangb...@nondot.org
          Reporter: andy.somervi...@gmail.com
                CC: djas...@google.com, kli...@google.com,
                    llvm-bugs@lists.llvm.org

Created attachment 19917
  --> https://bugs.llvm.org/attachment.cgi?id=19917&action=edit
minimal example of trailing comma issue

including trailing comma in initializer list causes formatter to switch
indentation style and splits short parameters one per line.


////////////////// BEGIN minimal example input //////////////////
#include <set>


void someFunction( std::set<int> & someSet )
{
    // initializer lists inside a constructor

    std::set<std::set<int >> firstSet{
        { 1, 2, 3, 5,}, // final comma internal initializer
        { 6, 7, 8,9}
    };

    std::set<std::set<int >> otherSet = {
        { 1, 2, 3, 5}, // no final comma internal initializer
        { 6, 7, 8,9}
    };

    auto middleSet = std::set<std::set<int >>{ 
        { 1, 2, 3, 5, }, // final comma external initializer
        { 6, 7, 8,9}, 
    };

    auto finalSet = std::set<std::set<int >>({ 
        { 1, 2, 3, 5 }, // final comma external initializer
        { 6, 7, 8,9}, 
    });
}
////////////////// END minimal example input //////////////////


$ clang-format-5.0 -style=llvm ./minimal_initializer_test.cpp 

////////////////// BEGIN minimal example output //////////////////
#include <set>

void someFunction(std::set<int> &someSet) {
  // initializer lists inside a constructor

  std::set<std::set<int>> firstSet{{
                                       1,
                                       2,
                                       3,
                                       5,
                                   }, // final comma internal initializer
                                   {6, 7, 8, 9}};

  std::set<std::set<int>> otherSet = {
      {1, 2, 3, 5}, // no final comma internal initializer
      {6, 7, 8, 9}};

  auto middleSet = std::set<std::set<int>>{
      {
          1,
          2,
          3,
          5,
      }, // final comma external initializer
      {6, 7, 8, 9},
  };

  auto finalSet = std::set<std::set<int>>({
      {1, 2, 3, 5}, // final comma external initializer
      {6, 7, 8, 9},
  });
}
////////////////// END minimal example output //////////////////

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to