Odd Constructor Syntax

I've found out that on g++ the following code compiles:
1
2
3
4
struct Foo
{
    ****const****const****& Foo()   {}
};
I can put as many * and const as I want and one & at the end.
When it compiles it g++ gives the warning "control reaches end of non-void function" as it would with normal functions.
If I return something it will give the error expected when returning a value from the constructor.


Why does g++ allow this kind of declaration for a constructor?
It does not compile with Comeau:

http://www.comeaucomputing.com/tryitout/

Comeau C/C++ 4.3.10.1 (Oct 6 2008 11:28:09) for ONLINE_EVALUATION_BETA2
Copyright 1988-2008 Comeau Computing. All rights reserved.
MODE:strict errors C++ C++0x_extensions

"ComeauTest.c", line 3: error: invalid constructor declaration
****const****const****& Foo() {}
^

1 error detected in the compilation of "ComeauTest.c".


It's a bug in gcc, because this even compiles:

1
2
3
struct Foo {
    * Foo() {}
};


g++ --version
g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44)
But it does not compile with

# g++ --version
g++ (GCC) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

# g++ foo.cpp
foo.cpp:5: error: syntax error before `)' token
# cat foo.cpp
1
2
3
4
5
6
7
8
9
10
#include <iostream>

struct Foo
{
    * Foo()   {std::cout << "function called" << std::endl;}
};

int main() {
   Foo f;
}

Where do you get this stuff?

Are you some sort of insane quality control specialist? (The kind of person that makes sure programs that ask for a number in '1'..'5' don't break when the user types 'quit', but to the (N+1)th degree?)
Last edited on
I like playing with things ( until I eventually break them... )
So I'm the kind of user who if the program asks to enter 1...5 tries with ROTFLMAOMGWTFBBQLOL123456789ABCDEF
In this way I find interesting features but at the same time I get a lot of bugs...
Topic archived. No new replies allowed.