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

    <tr>
        <th>Summary</th>
        <td>
            Clang tools: Running a frontend action on a header file with a force-included header file including the original file results in symbol redefinitions
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    Hi,

This issue to relates to the use of the [StructLayout](https://github.com/Viladoman/StructLayout) Visual Studio plugin for visualising the layout of structures. The plugin implements a FrontendAction to traverse the AST and collect information on structures for later display within Visual Studio.

When running the plugin, a header file is often the main input file. It will pass along many of the same arguments to the clang tool as if the corresponding .cpp file was being compiled. If running this tool on an Unreal Engine project, this means PCH will often be force-included. If that force-included PCH includes the original file, redefinition errors will occur, even with `#pragma once` in the main header file.

Hopefully this will provide a clearer explanation:

Main.h
```
#pragma once

#ifdef MAIN_H
#error "Main.h already included"
#endif
#define MAIN_H
```

PCH.h
```
#pragma once

#include "Main.h"
```

You can simulate the redefinition issue in clang itself by creating the files as described above and running clang like so:

"clang.exe Main.h --include PCH.h"

The output I get:
```
Main.h:4:2: error: "Main.h already included"
#error "Main.h already included"
 ^
1 error generated.
```

Thanks,
Nick
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVd9v2zYQ_mvol0MEhbLU-sEPblIjAdaiWLIOexrO5Em6hSIFknLq_34QJTtWMBTFAEOmqPvx3X3HjxgCN5ZoK8pPorxf4RBb57eW9Ct6HSzS6uD0afvAQt6J_F7ku-n53HIADmEgiA48GYwUxmVsCYZA4Oq0FOWnp-gHFX_DkxuiKO-F_NjG2AdR7ITcC7lvOLbDIVOuE3L_nQ1q16EVcr9wlBv4zmFAA09x0OygN0PDFmrn4Zg-cGDbpKQmuYwQQgoxeAoZPLd0duKuN9SRj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