This is an archive of the discontinued LLVM Phabricator instance.

Disallow dereferencing of void* in C++.
ClosedPublic

Authored by erichkeane on Oct 5 2022, 10:21 AM.

Details

Reviewers
shafik
Group Reviewers
Restricted Project
Restricted Project
Commits
rG6685e56ceddf: Disallow dereferencing of void* in C++.
Summary

as Discussed:
https://discourse.llvm.org/t/rfc-can-we-stop-the-extension-to-allow-dereferencing-void-in-c/65708

There is no good reason to allow this when the other compilers all
reject this, and it messes with SFINAE/constraint checking.

Diff Detail

Event Timeline

erichkeane created this revision.Oct 5 2022, 10:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 5 2022, 10:21 AM
erichkeane requested review of this revision.Oct 5 2022, 10:21 AM
erichkeane added inline comments.Oct 5 2022, 10:30 AM
clang/include/clang/Basic/DiagnosticSemaKinds.td
6941

Bikeshedding appreciated here :) Note that the diagnostic ALSO will show up in SFINAE/Concepts explanations, so we can't just say "will be removed" or something.

aaron.ballman added a reviewer: Restricted Project.Oct 5 2022, 10:35 AM
aaron.ballman added a subscriber: aaron.ballman.

Adding the vendors group due to the potential to break existing code.

cor3ntin added inline comments.
clang/include/clang/Basic/DiagnosticSemaKinds.td
6941

The usual terminology is dereferencing. "ISO C++ does not allow dereferencing a void*`"

erichkeane added inline comments.Oct 5 2022, 10:40 AM
clang/include/clang/Basic/DiagnosticSemaKinds.td
6941

Yeah, I thought the 'indirection' phrasing in the diagnostic above was strange as well, but figured I'd be consistent until someone came up with a good replacement here :)

jrtc27 added a subscriber: jrtc27.Oct 5 2022, 11:00 AM

What about __typeof__(*p)?

What about __typeof__(*p)?

Yes, that would also be an error in C++, as it is on all other compilers.

shafik accepted this revision as: shafik.Oct 5 2022, 5:27 PM
shafik added a subscriber: shafik.

LGTM

clang/docs/ReleaseNotes.rst
92
This revision is now accepted and ready to land.Oct 5 2022, 5:27 PM
erichkeane updated this revision to Diff 465707.Oct 6 2022, 5:58 AM
erichkeane marked an inline comment as done.

fix the release note spelling of permanent.

erichkeane added a subscriber: Restricted Project.Oct 6 2022, 6:19 AM

What about __typeof__(*p)?

Yes, that would also be an error in C++, as it is on all other compilers.

This actually relates to a use case I brought up in the RFC -- in an unevaluated context where the expression is only used to determine a type, it doesn't seem particularly harmful to allow the dereference. There might be generic programming cases where this comes up for people who exclusively use Clang, but I'm not 100% certain.

clang/docs/ReleaseNotes.rst
89–98

Wordsmithing

clang/include/clang/Basic/DiagnosticSemaKinds.td
6938–6939

We no longer use this diagnostic in C++, so might as well simplify it.

6942–6945

Based on the code search for people using that diagnostic flag, I don't think we need to do this -- it seems like only a very small number of projects disable that warning (at least from a code search on sourcegraph). We still need a separate diagnostic (because of the DefaultError, but I think we can re-use the old diagnostic group. WDYT?

6945–6947
clang/test/SemaCXX/disallow_void_deref.cpp
2

You should also add a RUN line showing the behavior when the diagnostic is not an error and is disabled entirely.

erichkeane marked 4 inline comments as done.Oct 6 2022, 7:08 AM
erichkeane added inline comments.
clang/include/clang/Basic/DiagnosticSemaKinds.td
6942–6945

SGTM. I'm not attached to it.

6945–6947

This is actually the result of clang-format! I'll undo it.

erichkeane updated this revision to Diff 465725.Oct 6 2022, 7:25 AM
erichkeane marked 2 inline comments as done.

Fix based on Aaron's comments.

This revision was landed with ongoing or failed builds.Oct 10 2022, 7:11 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptOct 10 2022, 7:11 AM