erichkeane created this revision. erichkeane added reviewers: clang-vendors, clang-language-wg. Herald added a project: All. erichkeane requested review of this revision.
Clang 16 changed to consider dereferencing a void* to be a warning-as-error, plus made this an error in SFINAE contexts, since this resulted in incorrect template instantiation. When doing so, the Clang 16 documentation was updated to reflect that this was likely to change again to a non-disablable error in the next version. As there has been no response to changing from a warning to an error, I believe this is a non-controversial change. This patch changes this to be an Error, consistent with the standard and other compilers. https://reviews.llvm.org/D150875 Files: clang/docs/ReleaseNotes.rst clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Sema/SemaExpr.cpp clang/test/SemaCXX/disallow_void_deref.cpp Index: clang/test/SemaCXX/disallow_void_deref.cpp =================================================================== --- clang/test/SemaCXX/disallow_void_deref.cpp +++ clang/test/SemaCXX/disallow_void_deref.cpp @@ -1,8 +1,7 @@ -// 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 +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s void f(void* p) { - (void)*p; // enabled-error{{ISO C++ does not allow indirection on operand of type 'void *'}} + (void)*p; // expected-error{{ISO C++ does not allow indirection on operand of type 'void *'}} } template<class T> @@ -11,6 +10,6 @@ }; 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 *'}} +// expected-error@-1{{static assertion failed}} +// expected-note@-2{{because 'void *' does not satisfy 'deref'}} +// expected-note@#FAILED_REQ{{because '*t' would be invalid: ISO C++ does not allow indirection on operand of type 'void *'}} Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -14957,7 +14957,7 @@ // be a pointer to an object type, or a pointer to a function type LangOptions LO = S.getLangOpts(); if (LO.CPlusPlus) - S.Diag(OpLoc, diag::ext_typecheck_indirection_through_void_pointer_cpp) + S.Diag(OpLoc, diag::err_typecheck_indirection_through_void_pointer_cpp) << OpTy << Op->getSourceRange(); else if (!(LO.C99 && IsAfterAmp) && !S.isUnevaluatedContext()) S.Diag(OpLoc, diag::ext_typecheck_indirection_through_void_pointer) Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -6981,9 +6981,8 @@ def ext_typecheck_indirection_through_void_pointer : ExtWarn< "ISO C does not allow indirection on operand of type %0">, InGroup<VoidPointerDeref>; -def ext_typecheck_indirection_through_void_pointer_cpp - : ExtWarn<"ISO C++ does not allow indirection on operand of type %0">, - InGroup<VoidPointerDeref>, DefaultError, SFINAEFailure; +def err_typecheck_indirection_through_void_pointer_cpp + : Error<"ISO C++ does not allow indirection on operand of type %0">; def warn_indirection_through_null : Warning< "indirection of non-volatile null pointer will be deleted, not trap">, InGroup<NullDereference>; Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -55,6 +55,8 @@ ----------------------------------------- - Clang won't search for coroutine_traits in std::experimental namespace any more. Clang will only search for std::coroutine_traits for coroutines then. +- Clang no longer allows dereferencing of a ``void*`` as an extension. Clang 16 + converted this to a warning-as-default-error as well as a SFINAE error. ABI Changes in This Version ---------------------------
Index: clang/test/SemaCXX/disallow_void_deref.cpp =================================================================== --- clang/test/SemaCXX/disallow_void_deref.cpp +++ clang/test/SemaCXX/disallow_void_deref.cpp @@ -1,8 +1,7 @@ -// 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 +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s void f(void* p) { - (void)*p; // enabled-error{{ISO C++ does not allow indirection on operand of type 'void *'}} + (void)*p; // expected-error{{ISO C++ does not allow indirection on operand of type 'void *'}} } template<class T> @@ -11,6 +10,6 @@ }; 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 *'}} +// expected-error@-1{{static assertion failed}} +// expected-note@-2{{because 'void *' does not satisfy 'deref'}} +// expected-note@#FAILED_REQ{{because '*t' would be invalid: ISO C++ does not allow indirection on operand of type 'void *'}} Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -14957,7 +14957,7 @@ // be a pointer to an object type, or a pointer to a function type LangOptions LO = S.getLangOpts(); if (LO.CPlusPlus) - S.Diag(OpLoc, diag::ext_typecheck_indirection_through_void_pointer_cpp) + S.Diag(OpLoc, diag::err_typecheck_indirection_through_void_pointer_cpp) << OpTy << Op->getSourceRange(); else if (!(LO.C99 && IsAfterAmp) && !S.isUnevaluatedContext()) S.Diag(OpLoc, diag::ext_typecheck_indirection_through_void_pointer) Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -6981,9 +6981,8 @@ def ext_typecheck_indirection_through_void_pointer : ExtWarn< "ISO C does not allow indirection on operand of type %0">, InGroup<VoidPointerDeref>; -def ext_typecheck_indirection_through_void_pointer_cpp - : ExtWarn<"ISO C++ does not allow indirection on operand of type %0">, - InGroup<VoidPointerDeref>, DefaultError, SFINAEFailure; +def err_typecheck_indirection_through_void_pointer_cpp + : Error<"ISO C++ does not allow indirection on operand of type %0">; def warn_indirection_through_null : Warning< "indirection of non-volatile null pointer will be deleted, not trap">, InGroup<NullDereference>; Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -55,6 +55,8 @@ ----------------------------------------- - Clang won't search for coroutine_traits in std::experimental namespace any more. Clang will only search for std::coroutine_traits for coroutines then. +- Clang no longer allows dereferencing of a ``void*`` as an extension. Clang 16 + converted this to a warning-as-default-error as well as a SFINAE error. ABI Changes in This Version ---------------------------
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits