[llvm-bugs] [Bug 46352] New: PCH header is still parsed and included leading to redefinition errors (does not happen with clang-cl/GCC style pch)

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jun 16 10:44:51 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46352

            Bug ID: 46352
           Summary: PCH header is still parsed and included leading to
                    redefinition errors (does not happen with clang-cl/GCC
                    style pch)
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: nok.raven at gmail.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

// test.cpp
#include <pch.hpp>
int main() {}

// pch.hpp
#include <pch.hpp>

>clang++ -c pch.hpp -I. -Xclang -emit-pch -o pch.pch

>clang++ test.cpp -I. -Xclang -include-pch -Xclang pch.pch -o test
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>

>clang++ -c -x c++-header pch.hpp -I. -o pch.hpp.gch
>clang++ test.cpp -I. -o test

>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"

>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"

>g++ -c -x c++-header pch.hpp -I. -o pch.hpp.gch
>g++ test.cpp -I. -o test

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200616/e688c127/attachment-0001.html>


More information about the llvm-bugs mailing list