<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 - PCH header is still parsed and included leading to redefinition errors (does not happen with clang-cl/GCC style pch)"
href="https://bugs.llvm.org/show_bug.cgi?id=46352">46352</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>PCH header is still parsed and included leading to redefinition errors (does not happen with clang-cl/GCC style pch)
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</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>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>nok.raven@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>// test.cpp
#include <pch.hpp>
int main() {}
// pch.hpp
#include <pch.hpp>
<span class="quote">>clang++ -c pch.hpp -I. -Xclang -emit-pch -o pch.pch</span >
<span class="quote">>clang++ test.cpp -I. -Xclang -include-pch -Xclang pch.pch -o test</span >
In file included from test.cpp:1:
.\pch.hpp:1:7: error: redefinition of 'X'
class X {};
^
test.cpp:1:1: note: '.\pch.hpp' included multiple times, additional include
site here
#include <pch.hpp>
^
test.cpp:1:10: note: '.\pch.hpp' included multiple times, additional include
site here
#include <pch.hpp>
^
.\pch.hpp:1:7: note: unguarded header; consider using #ifdef guards or #pragma
once
class X {};
^
1 error generated.
Clang with GCC style PCH, Clang-cl, GCC, and MSVC are fine:
// pch.cpp
#include <pch.hpp>
<span class="quote">>clang++ -c -x c++-header pch.hpp -I. -o pch.hpp.gch
>clang++ test.cpp -I. -o test</span >
<span class="quote">>clang-cl -c pch.cpp -I. -Yc"pch.hpp" -Fo"pch.o" -Fp"pch.pch"
>clang-cl test.cpp -I. -Yu"pch.hpp" -Fp"pch.pch"</span >
<span class="quote">>cl -c pch.cpp -I. -Yc"pch.hpp" -Fo"pch.o" -Fp"pch.pch"
>cl -c test.cpp -I. -Yu"pch.hpp" -Fp"pch.pch" -Fo"test.o"</span >
<span class="quote">>g++ -c -x c++-header pch.hpp -I. -o pch.hpp.gch
>g++ test.cpp -I. -o test</span ></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>