5-2-7 and void pointer conversions

Moderators: david ward, misra cpp

Post Reply
Posts: 14
Joined: Fri Jul 20, 2007 7:54 pm

5-2-7 and void pointer conversions

Post by rgamble » Fri Jul 13, 2018 3:32 am

Are conversions between pointers to void and pointers to object types a violation of rule 5-2-7? It isn't clear what "object with pointer type" means here (or "unrelated pointer type" for that matter). Specifically, are either of the casts below a violation of Rule 5-2-7?

Code: Select all

void bar(int *ip, void *vp) {
    ip = static_cast<int *>(vp);
    vp = static_cast<void *>(ip);

misra cpp
Posts: 151
Joined: Mon Jun 02, 2008 1:55 pm
Company: MISRA

Re: 5-2-7 and void pointer conversions

Post by misra cpp » Tue Jul 17, 2018 2:10 pm

It was not intended that 5-2-7 should address the use of void* - though we recognise that this could be more clearly expressed, and will be clarified in the next issue

5-2-8 bans casts from void* to other pointer types, but casting a pointer type to void* is permitted
Posted by and on behalf of
the MISRA C++ Working Group

Post Reply

Return to “6.5 Expressions (C++)”