http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51515

             Bug #: 51515
           Summary: Unable to forward declare nested functions
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: elba...@gmail.com


Attempting to forward-declare a nested function results in a compiler error. 
This used to work in gcc-3.4.

eg

void f()
{
  void g(void);

  g();

  void g() {}
}


compiling this produces the following errors:

cc    -c -o tfn.o tfn.c
tfn.c: In function ‘f’:
tfn.c:5: error: static declaration of ‘g’ follows non-static declaration
tfn.c:3: note: previous declaration of ‘g’ was here

applying 'static' to the function declaration or definition, which is what the
error message might suggest the compiler wants,  produces:

void f()
{
  static void g(void);
  g();
  static void g(){};
}

cc    -c -o tfn.o tfn.c
tfn.c: In function ‘f’:
tfn.c:3: error: invalid storage class for function ‘g’
tfn.c:5: error: invalid storage class for function ‘g’
tfn.c:5: warning: conflicting types for ‘g’
tfn.c:5: error: static declaration of ‘g’ follows non-static declaration
tfn.c:4: note: previous implicit declaration of ‘g’ was here

Reply via email to