S
Scott Brady Drummonds
A coworker of mine tried compiling the following code in two versions of the
same compiler:
<quote>
class A;
class B {
public:
int b;
int printSomething () throw (A);
};
class A {
int a;
};
int main() {
B bb;
return 0;
}
</quote>
In one, the code compiled. In the newer version of the same compiler (GCC,
FWIW) it complained:
<quote>
test.cpp:6: invalid use of undefined type `struct A'
test.cpp:1: forward declaration of `struct A'
</quote>
We were talking about the reason for the failure and unable to come to a
consensus as to why the newer version was complaining. As far as I
understand it, I don't know why any compiler would compile this code. It
would seem to me that the exception specification for 'printSomething' would
have to know the size of the variable passed as its parameter. Since that
variable's type, A, has been declared but not defined, the size is unknown.
So, in my estimation, the newer version is correct in erroring and the older
one was likely sloppy in allowing compilation.
What are your thoughts?
Scott
same compiler:
<quote>
class A;
class B {
public:
int b;
int printSomething () throw (A);
};
class A {
int a;
};
int main() {
B bb;
return 0;
}
</quote>
In one, the code compiled. In the newer version of the same compiler (GCC,
FWIW) it complained:
<quote>
test.cpp:6: invalid use of undefined type `struct A'
test.cpp:1: forward declaration of `struct A'
</quote>
We were talking about the reason for the failure and unable to come to a
consensus as to why the newer version was complaining. As far as I
understand it, I don't know why any compiler would compile this code. It
would seem to me that the exception specification for 'printSomething' would
have to know the size of the variable passed as its parameter. Since that
variable's type, A, has been declared but not defined, the size is unknown.
So, in my estimation, the newer version is correct in erroring and the older
one was likely sloppy in allowing compilation.
What are your thoughts?
Scott