Clang will soon disallow dereferencing void* pointers in C++

22 views
Skip to first unread message

Derek Schuff

unread,
May 25, 2023, 1:48:43 PM5/25/23
to emscripten-discuss
tl;dr: if you're currently using the -Wno-void-ptr-dereference flag, you'll need to fix your code to stop dereferencing void pointers in C++

Hello emscripten users,
Dereferencing a void* pointer is invalid in C++ but until recently Clang allowed it (by disabling the default warning-as-error). A change recently landed in clang that will remove the option to do this, so I wanted to give you all as early of a warning as possible that you may need to fix your code (hopefully not; if you're not using -Wno-void-ptr-dereference you should be fine). I expect this change to eventually roll into an emscripten release in the next few weeks.
Thanks!
-Derek

Steven Johnson

unread,
May 30, 2023, 12:24:43 PM5/30/23
to emscripte...@googlegroups.com
...how was that ever legal (or useful) in the first place?

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAAEAhveRENM0o-ov%3DUT_yF16KboOGwhiLubhFx7HtWNb%3Dg8mrQ%40mail.gmail.com.

Floh

unread,
May 31, 2023, 11:03:16 AM5/31/23
to emscripten-discuss
Probably for esoteric reasons where no actual 'runtime dereference' happens, like sizeof(*p).

Apparently, the size of void is 1 :)

Mark Sibly

unread,
May 31, 2023, 4:20:58 PM5/31/23
to emscripte...@googlegroups.com
> Apparently, the size of void is 1 :)

Didn't know you could do that! Don't know if I agree with 1 though, I'd go for 0 myself...

The only other place I know where void can be treated as a value is in return statements, eg:

return *void_ptr;

...and I can sort of see how this might be useful in generic code.

Reply all
Reply to author
Forward
0 new messages