$ cat >text.cxx struct foo { }; struct bar { foo foo (); }; $ g++ --version g++ (GCC) 3.3.4 (Debian 1:3.3.4-12) $ g++ -c test.cxx test.cxx:8: error: declaration of `foo bar::foo()' test.cxx:2: error: changes meaning of `foo' from `struct foo' $ g++-3.4 --version g++-3.4 (GCC) 3.4.2 (Debian 3.4.2-2) $ g++ -c test.cxx test.cxx:8: error: declaration of `foo bar::foo()' test.cxx:2: error: changes meaning of `foo' from `struct foo' This code compiles fine with both intel c++ 8.1 and current comeau online.
No GCC is correct, foo cannot be redefined in the same class where you use it differently.
And what about this: class foo { }; struct bar { ::foo foo (); }; illegal too? And this struct bar { struct foo { }; foo foo (); }; should definitely be illegal, right?
The first example is valid because ::foo is explicantly named but the second is invalid. Basically in C++ you have to "reparse" the struct again after finishing the struct and the standard says that if the type is different than before it is an error.
> the second is invalid however it is accepted by g++ 3.4.2 > Basically in C++ you have to "reparse" the struct again after finishing > the struct and the standard says that if the type is different than > before it is an error. You mean the type of symbol is different or the type is different? I always thought that types and functions form separate symbol spaces. If what you are saying is true then the following is illegal too, right? struct foo { }; foo foo ();
*** Bug 18320 has been marked as a duplicate of this bug. ***
Reopening to ...
Mark as a dup of bug 17353. *** This bug has been marked as a duplicate of 17353 ***