[Bug c++/28728] New: function declaration inside function

mceier at gmail dot com gcc-bugzilla@gcc.gnu.org
Mon Aug 14 20:07:00 GMT 2006

With GCC it is possible to declare function inside other function. I think the
code below should not compile because of ambiguity - compiler can create a
variable ( test ) and call constructor of class Test ( Test::Test() ) or
interpret this as function declaration as GCC does ( which is invalid because
of place where the function was declared - I'm not a C++ expert, so I'm asking
if it is valid to declare a function inside other function and use it as all
normal functions ?? )
Sorry for my english

The Code:

#include <cstdio>
class Test {
        void SomeFunction(void) const;
Test::Test(void) { printf("%s\n",__FUNCTION__); }
void Test::SomeFunction(void) const { printf("%s\n",__FUNCTION__); }
Test::~Test(void) { printf("%s\n",__FUNCTION__); }
int main(void) {
        // Declaring function in global scope, instead of variable of type
        Test test() ;
        return 0;
// Defining function which declaration is inside main:
Test test() { return Test(); }

           Summary: function declaration inside function
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mceier at gmail dot com


More information about the Gcc-bugs mailing list