[prev in list] [next in list] [prev in thread] [next in thread] 

List:       llvm-bugs
Subject:    [llvm-bugs] [Bug 63619] Clang-format SortIncludes does not allow main headers in <> instead of ""
From:       LLVM Bugs via llvm-bugs <llvm-bugs () lists ! llvm ! org>
Date:       2023-06-30 13:03:43
Message-ID: 20230630130343.1ad924954e2c44e3 () email ! llvm ! org
[Download RAW message or body]

[Attachment #2 (text/html)]

<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/63619>63619</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Clang-format SortIncludes does not allow main headers in &lt;&gt; instead \
of &quot;&quot;  </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          aristotelos
      </td>
    </tr>
</table>

<pre>
    Clang-format has advanced detection of the &quot;main header&quot; of a C++ file \
to keep it as the first include. However, this only works if the main header file is \
referenced using double quotes (`&quot;myproject/MyClass.h&quot;`), not if the main \
header is referenced using angle brackets (`&lt;myproject/MyClass.h&gt;`). This is \
invalid because there is no strict rule to put main header includes into double \
quotes.

## Root cause

Clang-format has [a hard-coded check that the main header file should be included \
with double quotes](https://github.com/llvm/llvm-project/blob/d32fb5e5f51dedba495301073b9250f84ac6d8a8/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp#L237). \


## Reproduction scenario

Project layout:
```
myproject
   include
      myproject
 MyClass.h
   src
       MyClass.cc
```

.clang-format file:
```
SortIncludes: true
```

MyClass.cc:
```
#include &lt;myproject/MyClass.h&gt;
#include &lt;anotherproject/OtherClass.h&gt;
```

Clang-format will reformat this to:
```
#include &lt;anotherproject/OtherClass.h&gt;
#include &lt;myproject/MyClass.h&gt;
```
because it doesn&apos;t recognize `&lt;myproject/MyClass.h&gt;` as the main header \
reference.

Workaround: change MyClass.cc to:
```
#include &quot;myproject/MyClass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83CYUcunt7E0I6m1A27KFalszHFc1qyydHl8zgfn7Gj42uCzvFh3qPs2lkgoT6B9TERmvxSZhmlXAzBtT_slmMN2d_GMv4JAAD__2QEc1A">



[Attachment #3 (text/plain)]

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic