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

            Bug ID: 43988
           Summary: formatting broken when using inline if inside of
                    templates in class initializer list
           Product: clang
           Version: 9.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Formatter
          Assignee: unassignedclangb...@nondot.org
          Reporter: steffen.seck...@tum.de
                CC: djas...@google.com, kli...@google.com,
                    llvm-bugs@lists.llvm.org

clang-format gets confused when dealing with inline ifs in templates within
class initializer lists.


The behavior got worse with clang-format-9, as the indentation of the following
entries in the initializer list are wrongly indented.


==============using braces and clang-format-9==============

template <int someInt> class Base { Base(int i){}; };

template <bool someBool> class Derived : public Base<someBool ? 2 : 3> {
public:
  Derived()
      : Base<(someBool ? 2 : 3)>{35}, _someMember{3}, _someMember2{2},       //
<-- desired indentation
        _someMember3{2} {}

private:
  int _someMember;
  int _someMember2;
  int _someMember3;
};

==============without braces and clang-format-9==============

template <int someInt> class Base { Base(int i){}; };

template <bool someBool> class Derived : public Base<someBool ? 2 : 3> {
public:
  Derived()
      : Base < someBool
      ? 2
      : 3 > {35},
  _someMember{3}, _someMember2{2}, _someMember3{2} {}                        
// <-- wrong indentation

private:
  int _someMember;
  int _someMember2;
  int _someMember3;
};

==============without braces and clang-format-8==============

template <int someInt> class Base { Base(int i){}; };

template <bool someBool> class Derived : public Base<someBool ? 2 : 3> {
public:
  Derived()
      : Base < someBool
      ? 2
      : 3 > {35},
      _someMember{3}, _someMember2{2}, _someMember3{2} {}                     
// <-- slightly better indentation, but still wrong.

private:
  int _someMember;
  int _someMember2;
  int _someMember3;
};

============================================================
clang-format-9 version:
9.0.1-+2019110812332108004e858e4ac00-1~exp1~20191108215024.72
clang-format-8 version: 8.0.1-svn369350-1~exp1~20190820121219.79

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

Reply via email to