llvm-project/clang/test/SemaCXX/disallow_void_deref.cpp
Erich Keane 6685e56ced Disallow dereferencing of void* in C++.
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.

Differential Revision: https://reviews.llvm.org/D135287
2022-10-10 07:11:46 -07:00

17 lines
622 B
C++

// RUN: %clang_cc1 -fsyntax-only -verify=enabled,sfinae -std=c++20 %s
// RUN: %clang_cc1 -fsyntax-only -verify=sfinae -std=c++20 -Wno-void-ptr-dereference %s
void f(void* p) {
(void)*p; // enabled-error{{ISO C++ does not allow indirection on operand of type 'void *'}}
}
template<class T>
concept deref = requires (T& t) {
{ *t }; // #FAILED_REQ
};
static_assert(deref<void*>);
// sfinae-error@-1{{static assertion failed}}
// sfinae-note@-2{{because 'void *' does not satisfy 'deref'}}
// sfinae-note@#FAILED_REQ{{because '*t' would be invalid: ISO C++ does not allow indirection on operand of type 'void *'}}