I'm trying to make some code MISRA complaint and I have the following piece of code:
static void DBusCallback(GObject *object, GAsyncResult *res, gpointer user_data) {
std::string * const tmp = reinterpret_cast<std::string*>(user_data);
...
where DBusCallback is a callback for call_DBus:
(void)call_DBus(proxy, NULL, &DBusCallback, reinterpret_cast<void*>(new std::string(user_data)));
//last pram is the user_data from the callback
It compiles and runs ok, but I have the following MISRA warning at string conversion from gpointer: MISRA.CAST.PTR.UNRELATED : Object of pointer type 'gpointer' cast to unrelated type 'string*'
The rule is: MISRA-C++ Rule 5-2-7 (required): An object with pointer type shall not be converted to an unrelated pointer type, either directly or indirectly. [Unspecified 5.2.10(7)] Rationale The result of converting from a pointer to an unrelated type is unspecified.
Any idea to avoid this warning?
gpointer
? I can't see how it could work unless it is a pointer tostd::string
. – juanchopanza&DBusCallback
either... – Lindydancer