ycm-core / YouCompleteMe

A code-completion engine for Vim
http://ycm-core.github.io/YouCompleteMe/
GNU General Public License v3.0
25.45k stars 2.81k forks source link

Project is compiling fine but YCM is displaying errors #3666

Closed smadurange closed 4 years ago

smadurange commented 4 years ago

I'm getting YCM warnings that doesn't seem to be caused by real issues. I'm a beginner, so I apologise if this is a trivial issue. But I could not find a fix myself for this.

Thank you for adhering to this process! It ensures your issue is resolved quickly and that neither your nor our time is needlessly wasted.

Issue Details

I'm getting following errors when I'm using std::mutex and spdlog libraries:

With std::mutex:

Call to deleted constructor of 'std::mutex'                                                 
/../lib64/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../include/c++/9.3.0/bits/std_mutex.h:94:5:
note: 'mutex' has been explicitly marked deleted here

With spdlog::trace("Hello%d", 1) I get:

No matching function for call to 'trace'                                                    
/usr/include/spdlog/spdlog.h:187:13:
note: candidate function template not viable: requires single argument 'msg', but 2 arguments were provided

Note that spdlog issue only happens when I use string formatting with %s or %d. When I just do something like spdlog::info("Hello") I do not get any errors from YCM.

I installed spdlog using pacman (I'm on Arch Linux x64) and I'm using CMake and Ninja to build the project with clang compiler. My .vimrc file:

" General configuration options
 set number
 set encoding=utf-8
 syntax on

" YouCompleteMe
" clangd-based completer for YouCompleteMe
let g:ycm_clangd_binary_path="/usr/bin/clangd"
let g:ycm_global_ycm_extra_conf="/home/sadeep/.vim/pack/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py"
set runtimepath+=~/.vim/pack/YouCompleteMe/

" Indentation
filetype plugin indent on
set tabstop=4
set shiftwidth=4
set expandtab

Minimal example: Test.hpp:

#pragma once

#include <mutex>
#include <boost/asio.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <spdlog/spdlog.h>

using boost::asio::ip::tcp;

class Test
{
   public:
         Test() : mtx(std::mutex())
         {
               spdlog::trace("Hello, world%d!", 2);
         }
  private:
        std::mutex mtx;
};

And in main.cpp, I just import this:

#include "Test.hpp"
int main(int argc, char *argv[])
{
      Test t;
       return 0;
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.16)

project(Test LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")

add_executable(test
     main.cpp
     Test.hpp
)

find_package(spdlog REQUIRED)
target_link_libraries(cmail spdlog::spdlog)

Diagnostic data

Output of vim --version

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Apr  4 2020 13:23:00)
Included patches: 1-510
Compiled by Arch Linux
Huge version without GUI.  Features included (+) or not (-):
+acl               -farsi             -mouse_sysmouse    -tag_old_static
+arabic            +file_in_path      +mouse_urxvt       -tag_any_white
+autocmd           +find_in_path      +mouse_xterm       +tcl/dyn
+autochdir         +float             +multi_byte        +termguicolors
-autoservername    +folding           +multi_lang        +terminal
-balloon_eval      -footer            -mzscheme          +terminfo
+balloon_eval_term +fork()            +netbeans_intg     +termresponse
-browse            +gettext           +num64             +textobjects
++builtin_terms    -hangul_input      +packages          +textprop
+byte_offset       +iconv             +path_extra        +timers
+channel           +insert_expand     +perl/dyn          +title
+cindent           +job               +persistent_undo   -toolbar
-clientserver      +jumplist          +popupwin          +user_commands
-clipboard         +keymap            +postscript        +vartabs
+cmdline_compl     +lambda            +printer           +vertsplit
+cmdline_hist      +langmap           +profile           +virtualedit
+cmdline_info      +libcall           +python/dyn        +visual
+comments          +linebreak         +python3/dyn       +visualextra
+conceal           +lispindent        +quickfix          +viminfo
+cryptv            +listcmds          +reltime           +vreplace
+cscope            +localmap          +rightleft         +wildignore
+cursorbind        +lua/dyn           +ruby/dyn          +wildmenu
+cursorshape       +menu              +scrollbind        +windows
+dialog_con        +mksession         +signs             +writebackup
+diff              +modify_fname      +smartindent       -X11
+digraphs          +mouse             -sound             -xfontset
-dnd               -mouseshape        +spell             -xim
-ebcdic            +mouse_dec         +startuptime       -xpm
+emacs_tags        +mouse_gpm         +statusline        -xsmp
+eval              -mouse_jsbterm     -sun_workshop      -xterm_clipboard
+ex_extra          +mouse_netterm     +syntax            -xterm_save
+extra_search      +mouse_sgr         +tag_binary        
   system vimrc file: "/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
Linking: gcc   -L. -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.30/core_perl/CORE  -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -L/usr/local/lib -Wl,--as-needed -o vim        -lm -ltinfo -lelf -lnsl    -lacl -lattr -lgpm -ldl   -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.30/core_perl/CORE -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -fstack-protector-strong -L/usr/local/lib  -L/usr/lib/perl5/5.30/core_perl/CORE -lperl -lpthread -ldl -lm -lcrypt -lutil -lc   -L/usr/lib -ltclstub8.6 -ldl -lz -lpthread -lm

Output of YcmDebugInfo

Printing YouCompleteMe debug information...
-- Client logfile: /tmp/ycm_2go5r198.log
-- Server Python interpreter: /usr/bin/python3
-- Server Python version: 3.8.2
-- Server has Clang support compiled in: False
-- Clang version: None
-- Extra configuration file found and loaded
-- Extra configuration path: /home/sadeep/.vim/pack/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py
-- C-family completer debug information:
--   Clangd running
--   Clangd process ID: 18953
--   Clangd executable: ['/usr/bin/clangd', '-header-insertion-decorators=0', '-limit-results=500']
--   Clangd logfiles:
--     /tmp/clangd_stderr08p8l9c0.log
--   Clangd Server State: Initialized
--   Clangd Project Directory: /home/sadeep/Repositories/cmail/src
--   Clangd Settings: {}
--   Clangd Compilation Command: ['clang-tool', '-Wall', '-Wextra', '-Werror', '-Wno-long-long', '-Wno-variadi
c-macros', '-fexceptions', '-DNDEBUG', '-DUSE_CLANG_COMPLETER', '-DYCM_EXPORT=', '-x', 'c++', '-isystem', 'cpp
/pybind11', '-isystem', 'cpp/whereami', '-isystem', 'cpp/BoostParts', '-isystem', '/usr/include/python3.8', '-
isystem', 'cpp/llvm/include', '-isystem', 'cpp/llvm/tools/clang/include', '-I', 'cpp/ycm', '-I', 'cpp/ycm/Clan
gCompleter', '-isystem', 'cpp/ycm/tests/gmock/gtest', '-isystem', 'cpp/ycm/tests/gmock/gtest/include', '-isyst
em', 'cpp/ycm/tests/gmock', '-isystem', 'cpp/ycm/tests/gmock/include', '-isystem', 'cpp/ycm/benchmarks/benchma
rk/include', '-std=c++11', '/home/sadeep/Repositories/cmail/src/Test.hpp']
-- Server running at: http://127.0.0.1:54059
-- Server process ID: 18912
-- Server logfiles:
--   /tmp/ycmd_54059_stdout_25wiu4bi.log
--   /tmp/ycmd_54059_stderr_s0td6per.log

Output of YcmDiags

Test.hpp|6 col 10 error| In included file: 'spdlog/fmt/bundled/core.h' file not found /usr/include/spdlog/    fmt/fmt.h:22:10: note: error occurred here [pp_file_not_found]                                            
  2 Test.hpp|13 col 14 error| Call to deleted constructor of 'std::mutex' /../lib64/gcc/x86_64-pc-linux-gnu/9.    3.0/../../../../include/c++/9.3.0/bits/std_mutex.h:94:5: note: 'mutex' has been explicitly marked deleted     here [ovl_deleted_init]
  3 Test.hpp|15 col 9 error| No matching function for call to 'trace' /usr/include/spdlog/spdlog.h:187:13: not    e: candidate function template not viable: requires single argument 'msg', but 2 arguments were provided [    ovl_no_viable_function_in_call]

Output of git rev-parse HEAD in YouCompleteMe installation directory

97150c0b1fde6a7e3f3eea0abab7d114774dd1af

OS version, distribution, etc.

Arch Linux x64

bstaletic commented 4 years ago
Test.hpp|6 col 10 error| In included file: 'spdlog/fmt/bundled/core.h' file not found /usr/include/spdlog/    fmt/fmt.h:22:10: note: error occurred here [pp_file_not_found]

Arch package doesn't contain /usr/include/spdlog/fmt/bundled. That seems to be the fmt library, so install it properly and use the proper include paths. Or clone the entire spdlog locally.

Test.hpp|13 col 14 error| Call to deleted constructor of 'std::mutex' /../lib64/gcc/x86_64-pc-linux-gnu/9.    3.0/../../../../include/c++/9.3.0/bits/std_mutex.h:94:5: note: 'mutex' has been explicitly marked deleted

The copy constructor of std::mutex is indeed deleted.

  Test.hpp|15 col 9 error| No matching function for call to 'trace' /usr/include/spdlog/spdlog.h:187:13: not    e: candidate function template not viable: requires single argument 'msg', but 2 arguments were provided [    ovl_no_viable_function_in_call]

There are 3 overloads of trace(). Two of which take something called string_view_t which is [fmt::string_basic_string_view<char](using string_view_t = fmt::basic_string_view;). Again, you will need fmt library in order to make this work.

 

Also, your project isn't producing a compile_command.json and you're loading .ycm_extra_conf.py, rendering the provided CMakeLists.txt irrelevant. Your flags say that you're using -std=c++11.

smadurange commented 4 years ago

@bstaletic Thanks for the explanation specially about the flags. Managed to fix some other issues I had thanks to that too. I updated .ycm_extra_conf.py to be similar to my cmake definition.

Also, you are right about the spdlog issue. Thanks!

bstaletic commented 4 years ago

You're welcome. For user support prefer gitter over github issues.