I have a function defined as follows:
void doSomethingWithCustomer (const Customer &customer);
One of my development engineers called it the following:
Customer *customer = order.getCustomer(); doSomethingWithCustomer (*customer);
Unfortunately, the getCustomer method can return nullptr if the order is not tied to the client. If getCustomer returns nullptr, then the application does not crash during a call to doSomethingWithCustomer , but rather inside a function that uses a client link.
Of course, the correct way to write this is to verify that the client is not nullptr first, and then call the function if we have a valid client. Usually we expect that if the function / method has a reference argument, then the caller checks its validity (which was not here), and not the argument verification function itself.
I know that Visual Studio 2010 (and earlier versions) passes links, actually passing a pointer, but I wonder if this is indicated somewhere in the C ++ standard. Is it possible to consider that a link is always passed as a pointer (personally, I would not rely on this, but it is interesting to know)?
Is it possible to tell Visual Studio that when transferring a link, it should automatically dereference it first and crash during a call, and then somewhere much deeper (this can be enough in the debug version)?
source share