Skip to content
Snippets Groups Projects
  • Krasimir Georgiev's avatar
    942d6e44
    [clang-format] Fix alignment of preprocessor trailing comments · 942d6e44
    Krasimir Georgiev authored
    Summary:
    This patch is a follow-up of https://reviews.llvm.org/rL304687, which fixed an
    overflow in the comment alignment code in clang-format. The token length of
    trailing comments of preprocessor directives is calculated incorrectly by
    including the text between consecutive directives. That causes them to not being
    aligned.
    
    For example, in this code with column limit 20
    ```
    #if A
    #else  // A
    int iiii;
    #endif // B
    ```
    the length of the token `// A` was wrongly calculated as 14 = 5 (the size of `// A\n`) plus 9 (the size of `int iiii;`) and so `// A` wouldn't be aligned with `// B` and this was produced:
    ```
    #if A
    #else // A
    int iiii;
    #endif // B
    ```
    
    This patch fixes this case.
    
    Reviewers: alexfh
    
    Reviewed By: alexfh
    
    Subscribers: cfe-commits, klimek
    
    Differential Revision: https://reviews.llvm.org/D33982
    
    git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@304912 91177308-0d34-0410-b5e6-96231b3b80d8
    942d6e44
    History
    [clang-format] Fix alignment of preprocessor trailing comments
    Krasimir Georgiev authored
    Summary:
    This patch is a follow-up of https://reviews.llvm.org/rL304687, which fixed an
    overflow in the comment alignment code in clang-format. The token length of
    trailing comments of preprocessor directives is calculated incorrectly by
    including the text between consecutive directives. That causes them to not being
    aligned.
    
    For example, in this code with column limit 20
    ```
    #if A
    #else  // A
    int iiii;
    #endif // B
    ```
    the length of the token `// A` was wrongly calculated as 14 = 5 (the size of `// A\n`) plus 9 (the size of `int iiii;`) and so `// A` wouldn't be aligned with `// B` and this was produced:
    ```
    #if A
    #else // A
    int iiii;
    #endif // B
    ```
    
    This patch fixes this case.
    
    Reviewers: alexfh
    
    Reviewed By: alexfh
    
    Subscribers: cfe-commits, klimek
    
    Differential Revision: https://reviews.llvm.org/D33982
    
    git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@304912 91177308-0d34-0410-b5e6-96231b3b80d8
Code owners
Assign users and groups as approvers for specific file changes. Learn more.