ccls icon indicating copy to clipboard operation
ccls copied to clipboard

Unable to parse precompiled headers

Open Nepfion opened this issue 4 years ago • 3 comments

Observed behavior

Minimal repository with described problem: https://gitlab.com/Nepfion/ccls_pch_bug There are some problems with precompiled headers generated with cmake target_precompile_header. When I configure the project and generate compile_commands.json with cmake. ccls fails to parse a precompiled header specified in CMakeLists.txt. I'm getting errors like use of undeclared identifier 'std' in main.cpp. However, if I uncomment line https://gitlab.com/Nepfion/ccls_pch_bug/-/blob/master/CMakeLists.txt#L5 (which literally includes an empty file), rebuild project and run :CocRestart in the main.cpp, then errors will gone and everything will be just fine.

My compile_commands.json (with commented inclusion of the empty file):

[
{
  "directory": "/home/nepfion/projects/vim_test_c++/build/Debug",
  "command": "/usr/bin/c++   -g -Winvalid-pch -x c++-header -include /home/nepfion/projects/vim_test_c++/build/Debug/CMakeFiles/test_exe.dir/cmake_pch.hxx -o CMakeFiles/test_exe.dir/cmake_pch.hxx.gch -c /home/nepfion/projects/vim_test_c++/build/Debug/CMakeFiles/test_exe.dir/cmake_pch.hxx.cxx",
  "file": "/home/nepfion/projects/vim_test_c++/build/Debug/CMakeFiles/test_exe.dir/cmake_pch.hxx.cxx"
},
{
  "directory": "/home/nepfion/projects/vim_test_c++/build/Debug",
  "command": "/usr/bin/c++   -g -Winvalid-pch -include /home/nepfion/projects/vim_test_c++/build/Debug/CMakeFiles/test_exe.dir/cmake_pch.hxx -o CMakeFiles/test_exe.dir/main.cpp.o -c /home/nepfion/projects/vim_test_c++/main.cpp",
  "file": "/home/nepfion/projects/vim_test_c++/main.cpp"
}
]

with inclusion:

[
{
  "directory": "/home/nepfion/projects/vim_test_c++/build/Debug",
  "command": "/usr/bin/c++   -g -include /home/nepfion/projects/vim_test_c++/include_me.h -Winvalid-pch -x c++-header -include /home/nepfion/projects/vim_test_c++/build/Debug/CMakeFiles/test_exe.dir/cmake_pch.hxx -o CMakeFiles/test_exe.dir/cmake_pch.hxx.gch -c /home/nepfion/projects/vim_test_c++/build/Debug/CMakeFiles/test_exe.dir/cmake_pch.hxx.cxx",
  "file": "/home/nepfion/projects/vim_test_c++/build/Debug/CMakeFiles/test_exe.dir/cmake_pch.hxx.cxx"
},
{
  "directory": "/home/nepfion/projects/vim_test_c++/build/Debug",
  "command": "/usr/bin/c++   -g -include /home/nepfion/projects/vim_test_c++/include_me.h -Winvalid-pch -include /home/nepfion/projects/vim_test_c++/build/Debug/CMakeFiles/test_exe.dir/cmake_pch.hxx -o CMakeFiles/test_exe.dir/main.cpp.o -c /home/nepfion/projects/vim_test_c++/main.cpp",
  "file": "/home/nepfion/projects/vim_test_c++/main.cpp"
}
]

Expected behavior

Precompiled headers should be parsed without the aforementioned hack.

Steps to reproduce

  1. git clone https://gitlab.com/Nepfion/ccls_pch_bug.git
  2. cd ccls_pch_bug
  3. nvim main.cpp
  4. :CMakeGenerate
  5. :CMakeBuild

System information

  • ccls version: ccls 0.20210330-3
  • clang version: 12.0.1
  • OS: Arch Linux
  • Editor: Neovim v.0.5.0
  • Language client (and version): coc 0.0.80

Configs

:CocConfig

{
"languageserver": {
  "ccls": {
    "command": "ccls",
    "args": ["--log-file=/tmp/ccls.log", "-v=1"],
    "filetypes": ["c", "cc", "cpp", "c++", "objc", "objcpp", "inl", "tpp", "cxx", "hxx"],
    "rootPatterns": [".ccls", "compile_commands.json"],
    "initializationOptions": {
      "cache": {
        "directory": "/tmp/ccls"
        },
      "client": {
        "snippetSupport": true
      },
      "index": {
        "onChange": true
      },
      "highlight": { "lsRanges": true}
      }
    }
  }
}

Also, I'm using cdelledonne/vim-cmake plugin.

Nepfion avatar Aug 29 '21 10:08 Nepfion

I have the same issue. Are there any updates on this?

Diadlo avatar Feb 02 '22 14:02 Diadlo

Is your /usr/bin/c++ clang, or is it GCC? In other words, are you compiling your actual code with clang, or are you compiling it with GCC?

madscientist avatar Feb 02 '22 15:02 madscientist

/usr/bin/c++ is GCC on my system. But I have just reproduced it with /usr/bin/clang++

Diadlo avatar Feb 07 '22 07:02 Diadlo