[llvm-bugs] [Bug 43988] New: formatting broken when using inline if inside of templates in class initializer list

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Nov 13 04:53:01 PST 2019


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: unassignedclangbugs at nondot.org
          Reporter: steffen.seckler at tum.de
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191113/ec08b3c9/attachment-0001.html>


More information about the llvm-bugs mailing list