G
George
Hi All,
I thought this would not compile because no return value is specified.
But it does compile and run (aix and xlc v7.0.)
Could someone kindly please point me to where in the spec this would be
covered?
Compiler Output is: '(W) A return value of type "int" is expected.'
Runtime Output is:
../a.out
Unknown exception
Unknown exception in foo2()
x = 804397472;
end
Here is the code:
//compile with xlc -qnooptimize -o <exe> <thisfile>.cpp -lc -lC
#include <iostream>
#include <exception>
#include <memory>
using namespace std;
struct A {
char* p;
};
auto_ptr<A> foo1() throw (exception)
{
auto_ptr<A> a(new A());
a->p = "filter this";
try{
if (2 > 1 ){
throw exception();
}else{
return a;
}
}
catch (...) {
cout << "Unknown exception" << endl ;
throw;
}
}
int foo2 ()
{
int x = 45;
try {
foo1();
return x;
} catch (...) {
cout <<"Unknown exception in foo2()" << endl;
}
}
int main()
{
int x = foo2();
cout << " x = " << x << endl;
cout << "end" << endl;
return 0;
}
I thought this would not compile because no return value is specified.
But it does compile and run (aix and xlc v7.0.)
Could someone kindly please point me to where in the spec this would be
covered?
Compiler Output is: '(W) A return value of type "int" is expected.'
Runtime Output is:
../a.out
Unknown exception
Unknown exception in foo2()
x = 804397472;
end
Here is the code:
//compile with xlc -qnooptimize -o <exe> <thisfile>.cpp -lc -lC
#include <iostream>
#include <exception>
#include <memory>
using namespace std;
struct A {
char* p;
};
auto_ptr<A> foo1() throw (exception)
{
auto_ptr<A> a(new A());
a->p = "filter this";
try{
if (2 > 1 ){
throw exception();
}else{
return a;
}
}
catch (...) {
cout << "Unknown exception" << endl ;
throw;
}
}
int foo2 ()
{
int x = 45;
try {
foo1();
return x;
} catch (...) {
cout <<"Unknown exception in foo2()" << endl;
}
}
int main()
{
int x = foo2();
cout << " x = " << x << endl;
cout << "end" << endl;
return 0;
}