ycm-core / YouCompleteMe

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

Unused macros warnings doesn't show up in vim. #3337

Closed Jialin closed 5 years ago

Jialin commented 5 years ago

Issue Prelude

Please complete these steps and check these boxes (by putting an x inside the brackets) before filing your issue:

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

Seems unused-macros warnings are swallowed by YCM.

I added an unused macros in my code, but the vim doesn't highlight the unused code.

For the following code:

#define UNUSED(i) ++i
int main() {
  return 0;
}

g++ -Weverything would generate unused-macros warning

A.cpp:1:9: warning: macro is not used [-Wunused-macros]
#define UNUSED(i) ++i
        ^
1 warning generated.

But seems YouCompleteMe swallow the warnings.

I expect the unused-macros warnings would be highlighted in vim.

The warnings is not be highlighted.

Diagnostic data

Output of vim --version

:version
VIM - Vi IMproved 8.1 (2018 May 18, compiled Feb 18 2019 23:51:40)
macOS version
Included patches: 1-950
Compiled by travis@Traviss-Mac.local
Huge version with MacVim GUI.  Features included (+) or not (-):
+acl               +cursorshape       +job               +mouse_urxvt       +signs             +vertsplit
+arabic            +dialog_con_gui    +jumplist          +mouse_xterm       +smartindent       +virtualedit
+autocmd           +diff              +keymap            +multi_byte        +startuptime       +visual
+autochdir         +digraphs          +lambda            +multi_lang        +statusline        +visualextra
-autoservername    +dnd               +langmap           -mzscheme          -sun_workshop      +viminfo
+balloon_eval      -ebcdic            +libcall           +netbeans_intg     +syntax            +vreplace
+balloon_eval_term +emacs_tags        +linebreak         +num64             +tag_binary        +wildignore
+browse            +eval              +lispindent        +odbeditor         +tag_old_static    +wildmenu
++builtin_terms    +ex_extra          +listcmds          +packages          -tag_any_white     +windows
+byte_offset       +extra_search      +localmap          +path_extra        -tcl               +writebackup
+channel           -farsi             +lua/dyn           +perl/dyn          +termguicolors     -X11
+cindent           +file_in_path      +menu              +persistent_undo   +terminal          -xfontset
+clientserver      +find_in_path      +mksession         +postscript        +terminfo          +xim
+clipboard         +float             +modify_fname      +printer           +termresponse      -xpm
+cmdline_compl     +folding           +mouse             +profile           +textobjects       -xsmp
+cmdline_hist      -footer            +mouseshape        +python/dyn        +textprop          -xterm_clipboard
+cmdline_info      +fork()            +mouse_dec         +python3/dyn       +timers            -xterm_save
+comments          +fullscreen        -mouse_gpm         +quickfix          +title
+conceal           -gettext           -mouse_jsbterm     +reltime           +toolbar
+cryptv            -hangul_input      +mouse_netterm     +rightleft         +transparency
+cscope            +iconv             +mouse_sgr         +ruby/dyn          +user_commands
+cursorbind        +insert_expand     -mouse_sysmouse    +scrollbind        +vartabs
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/Applications/MacVim.app/Contents/Resources/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_MACVIM -Wall -Wno-unknown-pragmas -pipe  -DMACOS_X -DMACOS_X_DARW
IN  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang   -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/us
r/local/opt/readline/lib -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/l
ib -L/usr/local/opt/readline/lib  -L/usr/local/lib -o Vim -framework Cocoa -framework Carbon       -lm  -lncurses -liconv -fra
mework AppKit   -fstack-protector  -L/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE

Output of YcmDebugInfo

Printing YouCompleteMe debug information...
-- Client logfile: /var/folders/zb/1jtztf1925x87s_9fw8rb5v1xc67bz/T/ycm_qyt5TF.log
-- Server Python interpreter: /usr/bin/python
-- Server Python version: 2.7.10
-- Server has Clang support compiled in: True
-- Clang version: clang version 7.0.0 (tags/RELEASE_700/final)
-- Extra configuration file found and loaded
-- Extra configuration path: /Users/jialino/ICPC/Ongoing/.ycm_extra_conf.py
-- C-family completer debug information:
--   Compilation database path: None
--   Flags: [u'-Werror', u'-Weverything', u'-Wno-c++98-compat', u'-Wno-double-promotion', u'-Wno-exit-time-destructors', u'-Wn
o-global-constructors', u'-Wno-missing-variable-declarations', u'-std=c++11', u'-x', u'c++', u'-isystem', u'/usr/include', u'-
isystem', u'/usr/local/include', u'-std=c++11', u'-resource-dir=/Users/jialino/.vim/bundle/YouCompleteMe/third_party/ycmd/thir
d_party/clang/lib/clang/7.0.0', u'-isystem', u'/Library/Developer/CommandLineTools/usr/include/c++/v1', u'-isystem', u'/Librar
y/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1', u'-isystem', u'/Library/Developer/CommandLineTools/SDKs/MacO
SX.sdk/usr/local/include', u'-isystem', u'/usr/local/include', u'-isystem', u'/Users/jialino/.vim/bundle/YouCompleteMe/third_p
arty/ycmd/third_party/clang/lib/clang/7.0.0/include', u'-isystem', u'/Library/Developer/CommandLineTools/usr/include', u'-isys
tem', u'/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include', u'-iframework', u'/Library/Developer/CommandLineTool
s/SDKs/MacOSX.sdk/System/Library/Frameworks', u'-iframework', u'/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Fr
ameworks', u'-fspell-checking']
--   Translation unit: /Users/jialino/ICPC/Ongoing/PHT.cpp
-- Server running at: http://127.0.0.1:58118
-- Server process ID: 34246
-- Server logfiles:
--   /var/folders/zb/1jtztf1925x87s_9fw8rb5v1xc67bz/T/ycmd_58118_stdout_erMQo8.log
--   /var/folders/zb/1jtztf1925x87s_9fw8rb5v1xc67bz/T/ycmd_58118_stderr_5YOjWp.log

Contents of YCM, ycmd and completion engine logfiles

2019-03-05 09:52:59,345 - ERROR - HTTPConnectionPool(host='127.0.0.1', port=58326): Max retries exceeded with url: /ready (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x113e61910>: Failed to establish a new connection: [Errno 61] Connection refused',))
2019-03-05 09:52:59,445 - ERROR - HTTPConnectionPool(host='127.0.0.1', port=58326): Max retries exceeded with url: /ready
2019-03-05 09:52:59,450 - DEBUG - No global extra conf, not calling method YcmCorePreload
2019-03-05 09:52:59,546 - INFO - Received ready request
2019-03-05 09:52:59,549 - INFO - Received event notification
2019-03-05 09:52:59,550 - DEBUG - Event name: BufferVisit
2019-03-05 09:52:59,563 - ERROR - Semantic completion not available for [u'cpp']
Traceback (most recent call last):
  File "/Users/jialino/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/server_state.py", line 98, in FiletypeCompletionAvailable
    self.GetFiletypeCompleter( filetypes )
  File "/Users/jialino/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/server_state.py", line 80, in GetFiletypeCompleter
    for filetype in current_filetypes ]
  File "/Users/jialino/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/server_state.py", line 64, in _GetFiletypeCompleterForFiletype
    completer = module.GetCompleter( self._user_options )
  File "/Users/jialino/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/completers/cpp/hook.py", line 32, in GetCompleter
    if ShouldEnableClangdCompleter( user_options ):
  File "/Users/jialino/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/completers/cpp/clangd_completer.py", line 160, in ShouldEnableClangdCompleter
    third_party_clangd = Get3rdPartyClangd()
  File "/Users/jialino/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/completers/cpp/clangd_completer.py", line 106, in Get3rdPartyClangd
    raise RuntimeError( error )
RuntimeError: clangd binary at None is out-of-date please update.
2019-03-05 09:52:59,564 - INFO - Received event notification
2019-03-05 09:52:59,565 - ERROR - clangd binary at None is out-of-date please update.
2019-03-05 09:52:59,565 - DEBUG - Event name: FileReadyToParse
2019-03-05 09:52:59,566 - INFO - Adding buffer identifiers for file: /Users/jialino/ICPC/Ongoing/A.cpp
2019-03-05 09:52:59,656 - INFO - Received filetype completion available request
2019-03-05 09:53:11,804 - INFO - Received debug info request
2019-03-05 09:53:31,085 - INFO - Received debug info request
serving on http://localhost:58326

OS version, distribution, etc.

MacOS Mojave Version 10.14.3 (18D109)

puremourning commented 5 years ago

g++ -Weverything would generate unused-macros warning

To confirm, is g++ here really clang (as you're on macOS) ?

bstaletic commented 5 years ago

Clang does have this warning and neither libclang nor clangd completers honour it.

On 5 March 2019 22:10:10 CET, Ben Jackson notifications@github.com wrote:

g++ -Weverything would generate unused-macros warning

To confirm, is g++ here really clang (as you're on macOS) ?

-- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/Valloric/YouCompleteMe/issues/3337#issuecomment-469858192

-- Sent from my Android device with K-9 Mail. Please excuse my brevity.

puremourning commented 5 years ago

I can imagine why. There are probably more unused macros in a given TU than used ones in most files. I suspect for that reason that this sort of warning is generated in a much later pass than the syntax-only checks run. But that would be a question for the clang developers.

It may be the "Incomplete" flag for example.

Anyway, yes clang does report this:

clang -o test -Weverything test.cc
test.cc:1:9: warning: macro is not used [-Wunused-macros]
#define UNUSED(i) ++i
        ^
1 warning generated.

But so does c-index-test:

BenMBP:test-unused-macro ben$ /Users/ben/Development/llvm/root/release/bin/c-index-test  -cursor-at=test.cc:1:1 -Weverything test.cc
0:0 Invalid Cursor => NoDeclFound
test.cc:1:9: warning: macro is not used [-Wunused-macros]
Number FIX-ITs = 0

But can confirm that when using 'Editing' mode in libclang this warning is not produced:

bash-3.2$ CINDEXTEST_EDITING=1 /Users/ben/Development/llvm/root/debug/bin/c-index-test -cursor-at=test.cc:1:1 -Weveryth
ing test.cc
0:0 Invalid Cursor => NoDeclFound

Therefore, this is not a YCM bug, nor a libclang one, it's an intentional compromise to prove the best overall experience for code completion and semantic analysis in real time.