vim-syntastic / syntastic

Syntax checking hacks for vim
Do What The F*ck You Want To Public License
11.3k stars 1.14k forks source link

error| expected ‘;’, identifier or ‘(’ before ‘_Bool’ #2331

Closed gray-image closed 4 years ago

gray-image commented 4 years ago

Hello, I'm quite new to the open source community, so I hope this issue report sufficiently conforms to community standards and expectation. I've tried to follow the linked contributing guidelines. I'm learning many new things: Linux as a desktop OS and vim (terminal: not gvim) as a code editor; I wanted to evaluate syntastic as a linter to replace the feature commonly standard in more "heavyweight" code editors like Eclipse. Is this a configuration problem that I can fix, or is this possibly a bug? Or is this expected behavior for some reason I'm just not grasping? Vim version: VIM - Vi IMproved 8.1 (2018 May 18, compiled Apr 15 2020 06:40:31) Included patches: 1-2269

Syntastic version: Syntastic version: 3.10.0-13 (Vim 801, Linux) Info for filetype: c Global mode: active Filetype c is active The current file will be checked automatically Available checkers: gcc make Currently enabled checker: gc

**Debugging info: syntastic_bool_error_demo.zip

** Messages maintainer: Bram Moolenaar Bram@vim.org "~/code/demo3/list/src/list.c" 7L, 79C syntastic: 5.428025: g:syntastic_version = '3.10.0-13 (Vim 801, Linux)' syntastic: 5.428385: &shell = '/bin/bash', &shellcmdflag = '-c', &shellpipe = '2>&1| tee', &shellquote = '', &shellredir = '>%s 2>&1', &shelltemp = 1, &shellxquote = '', &autochdir = 0, &shellxescape = '' syntastic: 5.429653: UpdateErrors (auto): default checkers syntastic: 5.430388: CacheErrors: default checkers syntastic: 5.431795: g:syntastic_aggregate_errors = 0 syntastic: 5.432245: getcwd() = '/home/user/code/demo3' syntastic: 5.438965: CacheErrors: Invoking checker: c/gcc syntastic: 5.443032: SyntasticMake: called with options: {'postprocess': [], 'errorformat': '%-G%f:%s:,%-G%f:%l: %#error: %#(Each undeclared identifier is reported only%.%#,%-G%f:%l: %#error: %#for each function it appears%.%#,%-GIn file included%.%#,%-G %#from %f:%l\,,%f :%l:%c: %trror: %m,%f:%l:%c: %tarning: %m,%f:%l:%c: %m,%f:%l: %trror: %m,%f:%l: %tarning: %m,%f:%l: %m', 'makeprg': 'gcc -x c -fsyntax-only -std=gnu99 -I. -I.. -Iinclude -Iincludes -I../include -I../includes -I/home/user/code/demo3/list/../log/include -I/home/user/cod e/demo3/list/./include /home/user/code/demo3/list/src/list.c'} syntastic: 5.459034: system: command run in 0.015463s syntastic: 5.459872: getLocList: checker c/gcc returned 1 syntastic: 5.460160: getLocList: checker c/gcc run in 0.020965s

My project tree:

.
├── list
│   ├── include
│   │   └── list.h
│   ├── src
│   │   ├── list.c
│   │   └── listPriv.h
│   └── .syntastic_c_config
└── log
    └── include
        └── log.h

My files:

// list.h
#ifndef LIST_H
#define LIST_H

#include <stdbool.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct List List;
typedef struct Node Node;

List* listCreate();

#ifdef __cplusplus
}
#endif

#endif
// list.c
#include "listPriv.h"
#include <log.h>

List* listCreate() {
  return NULL;
}
// listPriv.h
#ifndef PRIV_H
#define PRIV_H

#include <list.h>

#ifdef __cplusplus
extern "C" {
#endif

struct List {
  Node* head;
};

struct Node {
  void* data;
  Node* next;
}

#ifdef __cplusplus
}
#endif

#endif
// log.h
#ifndef LOG_H
#define LOG_H

#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

bool logIt( const char* fmt, ... );

#ifdef __cplusplus
}
#endif

#endif

.syntastic_c_config:

-I../log/include
-I./include

Syntastic section of my .vimrc:

let g:syntastic_always_populate_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 1
let g:syntastic_c_config_file = '.syntastic_c_config'

Problem/question: when I open list.c, syntastic (triggered by typing :Errors in vim) gives me this error:
log/include/log.h|11 col 1 error| expected ‘;’, identifier or ‘(’ before ‘_Bool’
Why is this error generated and what should I do to clear it?

If helpful, I've zipped and attached my project tree (content is the same as noted above). syntastic_bool_error_demo.zip

lcd047 commented 4 years ago

Why is this error generated

Because gcc, running with the options you configured, generates that message. Syntastic just shows you said message in a window. Try running this in a terminal:

cd /home/user/code/demo3
gcc -x c -fsyntax-only -std=gnu99 -I. -I.. -Iinclude -Iincludes -I../include -I../includes -I/home/user/code/demo3/list/../log/include -I/home/user/code/demo3/list/./include /home/user/code/demo3/list/src/list.c

(all that is from your logs above).

what should I do to clear it?

You could configure gcc with the appropriate flags for your project (cf. :h syntastic-c-gcc; cf. also :h syntastic-debug). Or you could tell syntastic to remove the message (cf. :h 'syntastic_quiet_messages'); but the rational approach is probably to be preferred.

That said, syntastic was meant to be a generic framework for linters, and as such its interface for checking C projects is less than great at its best. Depending on what you're doing it may or may not be suitable for you. You might consider using a specialized plugin such as YouCompleteMe instead.

gray-image commented 4 years ago

Not a bug: I need to be a little more careful scrubbing my code before appealing for help -- I think the problem here was a missing semicolon, which will notoriously lead to misleading errors. @lcd047 -- thanks for your suggestion: it helped nudge me in the right direction and understand syntastic better.