https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90632

            Bug ID: 90632
           Summary: Incorrect error diagnosis of variable declaration
           Product: gcc
           Version: 7.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tangyixuan at mail dot dlut.edu.cn
  Target Milestone: ---

GCC reports incorrect error diagnosis for error recovery.

For the following example, GCC should not report the undeclared variable after
error recovery when inserting the expected ';' in the first line.
$ cat s.c
static int c
static int a = 0;
static int func_1(int b);
static int  func_1(int b)
{ 
    return b;
}
int main (int argc, char* argv[])
{
    c = func_1(a);
    return 0;
}

$ gcc s.c
$ gcc --version
gcc (Ubuntu 4.8.5-4ubuntu8~14.04.2) 7.1.0

s.c:2:1: error:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘static’
 static int a = 0;
 ^~~~~~
s.c:10:5: error: ‘c’ undeclared (first use in this function)
     c = func_1(a);
     ^
s.c:10:16:  error: ‘a’ undeclared (first use in this function)
     c = func_1(a);
                         ^

$ clang-8.0 s.c
s.c:1:13: error: expected ';' after top level declarator
static int c
                  ^
                  ;
1 error generated.

Reply via email to