
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; }