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++/48386] "Cannot declare static function inside another function"


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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-03-31 13:10:12 UTC ---
This is not a bug, G++ is correct.

Are you trying to create a static variable?

The rules of C++ say that "B b( A() )" is interpreted as a declaration of a
function called "b" which takes a single parameter and returns "B" ... and as
the error says, you cannot declare a static variable at function scope.

To declare a static variable you need to do:

  static B b = B( A() );

or

  static B b = A();


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