[llvm-bugs] [Bug 43947] New: mis-indentation caused by macro/template instantiation

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Nov 8 09:30:46 PST 2019


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

            Bug ID: 43947
           Summary: mis-indentation caused by macro/template instantiation
           Product: clang
           Version: 9.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: spam at lukas-wirz.de
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org

The problem I'm observing is not limited to clang-format-9 but also exists in 7
and 8 (I'm using the versions that are packaged in Debian/testing).

The .clang-format I'm using contains only "BasedOnStyle:  LLVM".

The file that gets misformatted is 
<<<<<<<
#define container_output(container)                                           
\
  template <typename T>                                                       
\
  ostream &operator<<(ostream &s, const container<T> &v) {                    
\
    s << "{";                                                                 
\
    for (typename container<T>::const_iterator x(v.begin()); x != v.end();) { 
\
      s << *x;                                                                
\
      if (++x != v.end())                                                     
\
        s << ",";                                                             
\
    }                                                                         
\
    s << "}";                                                                 
\
    return s;                                                                 
\
  }

container_output(vector)

int myfunc() {
  return 0;
}
>>>>>>>

where the macro definition is irrelevant and can be outcommented. 
Instantiating the template defined in the macro (correct without semicolon)
causes the following function to be indented as:

<<<<<<<
container_output(vector)

    int myfunc() {
  return 0;
}
>>>>>>>

which is clearly two indentation-levels too many in the first line.

cheers, Lukas Wirz

-- 
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/20191108/6c30600f/attachment.html>


More information about the llvm-bugs mailing list