diff --git a/autoload/ale/handlers/gcc.vim b/autoload/ale/handlers/gcc.vim index 75964f72..eb42b27a 100644 --- a/autoload/ale/handlers/gcc.vim +++ b/autoload/ale/handlers/gcc.vim @@ -3,6 +3,8 @@ scriptencoding utf-8 " Description: This file defines a handler function which ought to work for " any program which outputs errors in the format that GCC uses. +let s:pragma_error = '#pragma once in main file' + function! s:AddIncludedErrors(output, include_lnum, include_lines) abort if a:include_lnum > 0 call add(a:output, { @@ -92,6 +94,11 @@ function! ale#handlers#gcc#HandleGCCFormat(buffer, lines) abort let l:include_lines = [] let l:included_filename = '' + if s:IsHeaderFile(bufname(bufnr(''))) + \&& l:match[5][:len(s:pragma_error) - 1] ==# s:pragma_error + continue + endif + call add(l:output, { \ 'lnum': l:match[2] + 0, \ 'col': l:match[3] + 0, diff --git a/test/handler/test_gcc_handler.vader b/test/handler/test_gcc_handler.vader index 990df2c5..72b7c541 100644 --- a/test/handler/test_gcc_handler.vader +++ b/test/handler/test_gcc_handler.vader @@ -77,3 +77,20 @@ Execute(GCC versions should be parsed correctly): \ 'This is free software; see the source for copying conditions. There is NO', \ 'warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.', \]) + +Execute(The GCC handler shouldn't complain about #pragma once for headers): + silent file! test.h + + AssertEqual + \ [], + \ ale#handlers#gcc#HandleGCCFormat(347, [ + \ ':1:1: warning: #pragma once in main file [enabled by default]', + \ ]) + + silent file! test.hpp + + AssertEqual + \ [], + \ ale#handlers#gcc#HandleGCCFormat(347, [ + \ ':1:1: warning: #pragma once in main file [enabled by default]', + \ ])