首页 > 解决方案 > Vim YouCompleteMe c++17:分解声明警告

问题描述

我想正确设置 YouCompleteMe,这样我就不会在 c++ 文件上收到以下警告:

...

auto [k,v] = mapIt; // some map iterator

...
decomposition declarations are a C++17 extension

我添加了

   flags.append( '-std=c++17' ) 

~/.vim/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py

并将以下内容添加到

~/.vimrc
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py'

标签: vimc++17youcompleteme

解决方案


I decided to remove the previous installation and do everything from the command line (assuming previous Vundle installation as recommended in YouCompleteMe docs).

# typical installation directory for vundle and pathogen
cd ~/.vim/bundle

# clone the repository for YouCompleteMe
git clone https://github.com/Valloric/YouCompleteMe.git
cd YouCompleteMe

# and all submodules
git submodule update --init --recursive

# install
python3 install.py --clang-completer

Next I created a simple ycm_extra_conf.py (without the .dot) containing:

def FlagsForFile ( filename, **kwargs ):
    return {
        'flags': ['-x', '-Wall', '-Wextra', '-Werror', '-std=c++2a']
    }

I added the c++2a flag, but c++17 should also work.

Then point to this file in your ~/.vimrc file.

let g:ycm_global_ycm_extra_conf = '$HOME/.vim/bundle/YouCompleteMe/ycm_extra_conf.py'

Note: you may have to add to your ~/.vimrc

Plugin 'Valloric/YouCompleteMe'  

in your vimrc file.

And run (from vim)

:PluginInstall

I didn't do these steps as I had installed YouCompleteMe previously.

This seems to have fixed the problem for me. Hope this can be useful for someone.


推荐阅读