cc: use '-x c*-header' for header files for C and C++ linters. (#4318)

When linting an header file in C or C++, `-x c-header` or
`-x c++-header` should be used instead of `-x c` or `-x c++`.

Using `-x c` or `-x c++` for headers files can lead to unused variables
and functions marked as static inlined as seen in #4096.

Using `-x c-header` or `-x c++-header` solve these issues.

The list of file extensions that are considered as header files can be
configured with the variables `g:ale_c_cc_header_exts` and
`g:ale_cpp_cc_header_exts`.
This commit is contained in:
Nicolas Pauss
2022-09-25 02:02:43 +02:00
committed by GitHub
parent a56d51ec1c
commit 78942df284
7 changed files with 73 additions and 2 deletions

View File

@@ -53,3 +53,19 @@ Execute(The -std flag should be replaced by parsed C flags):
let g:get_cflags_return_value = '-std=c99'
AssertLinter 'gcc', ale#Escape('gcc') . b:command_tail
Execute(The header files should use -x c-header):
let b:command_tail = substitute(b:command_tail, '-x c', '-x c-header', '')
call ale#test#SetFilename('../test-files/c/makefile_project/subdir/test.h')
AssertLinter 'gcc', ale#Escape('gcc') . b:command_tail
Execute(The header file extensions should be configurable):
let b:command_tail = substitute(b:command_tail, '-x c', '-x c-header', '')
call ale#assert#SetUpLinterTest('c', 'cc')
let b:ale_c_cc_header_exts = ['json']
call ale#test#SetFilename('../test-files/c/json_project/build/compile_commands.json')
AssertLinter 'gcc', ale#Escape('gcc') . b:command_tail

View File

@@ -53,3 +53,19 @@ Execute(The -std flag should be replaced by parsed C flags):
let g:get_cflags_return_value = '-std=c++11'
AssertLinter 'gcc', ale#Escape('gcc') . b:command_tail
Execute(The header files should use -x c++-header):
let b:command_tail = substitute(b:command_tail, '-x c++', '-x c++-header', '')
call ale#test#SetFilename('../test-files/c/hpp_file_project/test.hpp')
AssertLinter 'gcc', ale#Escape('gcc') . b:command_tail
Execute(The header file extensions should be configurable):
let b:command_tail = substitute(b:command_tail, '-x c++', '-x c++-header', '')
call ale#assert#SetUpLinterTest('cpp', 'cc')
let b:ale_cpp_cc_header_exts = ['json']
call ale#test#SetFilename('../test-files/c/json_project/build/compile_commands.json')
AssertLinter 'gcc', ale#Escape('gcc') . b:command_tail