This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/28728] New: function declaration inside function
- From: "mceier at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 14 Aug 2006 20:06:57 -0000
- Subject: [Bug c++/28728] New: function declaration inside function
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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 {
public:
Test(void);
void SomeFunction(void) const;
~Test(void);
};
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 test() ;
test().SomeFunction();
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
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28728