<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - libclang: unterminated conditional directive when generating preamble"
   href="https://bugs.llvm.org/show_bug.cgi?id=35029">35029</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>libclang: unterminated conditional directive when generating preamble
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>5.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>puremourning@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Since clang 5.0 (and currently in master), libclang reports "unterminated
conditional directive" when an "include guarded" file transitively includes
itself. Or at least that's how it appears.

There are two simple test cases, both of which compile fine when _not_ in
"editing" mode, but raise "unterminated conditional directive" when building a
preamble.

More info: <a href="https://github.com/Valloric/YouCompleteMe/issues/2795">https://github.com/Valloric/YouCompleteMe/issues/2795</a>

Tests reproduced with both clang 5.0 prebuilt binaries and a build of master as
of yesterday (Sat 21st October).

Test case 1: Header includes itself.

```circular.h
#ifndef TEST_C
#define TEST_C

#include "test.c"

int main() {}

#endif
```

Normal compilation

```
BeniMac:basic ben$ /Users/ben/Development/llvm.git-build/bin/c-index-test
-test-load-source local circular.h
// CHECK: <invalid loc>:2:9: macro definition=__llvm__
// CHECK: <invalid loc>:3:9: macro definition=__clang__
// CHECK: <invalid loc>:4:9: macro definition=__clang_major__
// CHECK: <invalid loc>:5:9: macro definition=__clang_minor__
// CHECK: <invalid loc>:6:9: macro definition=__clang_patchlevel__
...
works.
```

In editing mode:

```
BeniMac:basic ben$ CINDEXTEST_EDITING=1 
/Users/ben/Development/llvm.git-build/bin/c-index-test -test-load-source local
circular.h
// CHECK: circular.h:6:5: FunctionDecl=main:6:5 (Definition) Extent=[6:1 -
6:14]
// CHECK: circular.h:6:12: CompoundStmt= Extent=[6:12 - 6:14]
./circular.h:1:2: error: unterminated conditional directive
Number FIX-ITs = 0
```

Test case 2 (perhaps more realistic in editor scenarios, where users use
`-include b.h` to make completion work within `a.h`):

```a.h
#include "b.h"
#ifndef A_H
#define A_H
int main() {}
#endif /* A_H */
```

```b.h
#ifndef B_H
#define B_H
#include "a.h"
#endif /* B_H */
```

Again, compilation is fine until using the editor flags:

```
BeniMac:basic ben$ CINDEXTEST_EDITING=1 
/Users/ben/Development/llvm.git-build/bin/c-index-test -test-load-source local
a.h
// CHECK: a.h:4:5: FunctionDecl=main:4:5 (Definition) Extent=[4:1 - 4:14]
// CHECK: a.h:4:12: CompoundStmt= Extent=[4:12 - 4:14]
./a.h:2:2: error: unterminated conditional directive
Number FIX-ITs = 0
```

I _suspect_ (truly a guess), that this commit is the culprit, though I haven't
proven it: <a href="https://reviews.llvm.org/D15994#95a083c2">https://reviews.llvm.org/D15994#95a083c2</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>