Hi all,
Max found something that is important to know.
Apparently, gcc accepts "false" as a value for a pointer. So it is possible to write:
test_function(Test *t) ... test_function(false);
without triggering a compiler warning/error.
This hid a problem after refactoring a function method, resulting in a crash. See the mail below for more details.
Cheers, Johan
-----Original Message----- From: Maximilian Albert [mailto:Anhalter42@...173...] Sent: maandag 8 september 2008 15:13 To: Engelen, J.B.C. (Johan) Subject: Re: active_desktop removals
J.B.C.Engelen@...1578... schrieb:
We should check this, this is really bad compiler behaviour!
I just wrote a simple test program (attached below). It works fine as is, but when I replace the line
test_function(t);
with
test_function(false)
there is a runtime crash. However, even when compiling with -Wall there is no warning whatsoever. Interestingly, when I replace false with true in the function call, the code doesn't compile any more. But I'd think that false is just as well recognized as a boolean value as true is. Hmm, I think I will report this upstream on the gcc mailing list.
Max
===================================
#include <iostream>
using namespace std;
class Test { public: Test() {}
void print() { cout << "Hello, world!" << endl; } };
void test_function(Test *t) { t->print(); }
int main() { Test *t = new Test(); test_function(t); // replace t with false to trigger a runtime crash delete t; }
Hi all,
We should check this, this is really bad compiler behaviour!
I just wrote a simple test program (attached below). It works fine as is, but when I replace the line
test_function(t);
with
test_function(false)
there is a runtime crash.
Sorry, that doesn't seem to be true in the simple program I attached (I had a more complicated test case first but stripped it down before sending to Johan). Apparently, as long as you don't access internal data of the class, the function call is processed just fine even when you pass false instead of a valid pointer! Odd, indeed.
So you need to modify the test program a little to really trigger the crash:
#include <iostream>
using namespace std;
class Test { public: Test() { num=0; } void print() { cout << "num is " << num << endl;; }
private: int num; };
void test_function(Test *t) { t->print(); }
int main() { Test *t = new Test(); test_function(t); // replace t with false to trigger runtime crash delete t; }
J.B.C.Engelen@...1578... schrieb:
Apparently, gcc accepts "false" as a value for a pointer.
After a bit of investigation I found this bug report, which hopefully fixes the issue also for our case in recent gcc versions:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30860
Max
participants (2)
-
unknown@example.com
-
Maximilian Albert