This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/51515] New: Unable to forward declare nested functions


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: unassigned@gcc.gnu.org
        ReportedBy: elbacon@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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]