[clang] 09284e7 - [Clang] Reject `this void` explicit object parameters (CWG2915) (#108817)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 17 12:35:54 PDT 2024
Author: Mital Ashok
Date: 2024-09-17T21:35:49+02:00
New Revision: 09284e7eb20db88a9a5d60a591360ee35b256b7f
URL: https://github.com/llvm/llvm-project/commit/09284e7eb20db88a9a5d60a591360ee35b256b7f
DIFF: https://github.com/llvm/llvm-project/commit/09284e7eb20db88a9a5d60a591360ee35b256b7f.diff
LOG: [Clang] Reject `this void` explicit object parameters (CWG2915) (#108817)
https://cplusplus.github.io/CWG/issues/2915.html
Previously, `struct A { void f(this void); };` was accepted with `A::f`
being a member function with no non-object arguments, but it was still a
little wonky because it was still considered an explicit object member
function. Now, this is rejected immediately.
This applies to any language mode with explicit object parameters as
this is a DR (C++23 and C++26)
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaType.cpp
clang/test/CXX/drs/cwg29xx.cpp
clang/www/cxx_dr_status.html
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8228055a1d861a..d92b59334f8f32 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -170,6 +170,9 @@ Resolutions to C++ Defect Reports
in constant expressions. These comparisons always worked in non-constant expressions.
(`CWG2749: Treatment of "pointer to void" for relational comparisons <https://cplusplus.github.io/CWG/issues/2749.html>`_).
+- Reject explicit object parameters with type ``void`` (``this void``).
+ (`CWG2915: Explicit object parameters of type void <https://cplusplus.github.io/CWG/issues/2915.html>`_).
+
C Language Changes
------------------
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6fe87e92993a65..e8b64f3c5a0187 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4687,6 +4687,8 @@ def err_void_only_param : Error<
"'void' must be the first and only parameter if specified">;
def err_void_param_qualified : Error<
"'void' as parameter must not have type qualifiers">;
+def err_void_explicit_object_param : Error<
+ "explicit object parameter cannot have 'void' type">;
def err_ident_list_in_fn_declaration : Error<
"a parameter list without types is only allowed in a function definition">;
def ext_param_not_declared : ExtWarn<
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 11adfb0d7f3e98..950bd6db0359d1 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -5166,6 +5166,14 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
if (ParamTy.hasQualifiers())
S.Diag(DeclType.Loc, diag::err_void_param_qualified);
+ // Reject, but continue to parse 'float(this void)' as
+ // 'float(void)'.
+ if (Param->isExplicitObjectParameter()) {
+ S.Diag(Param->getLocation(),
+ diag::err_void_explicit_object_param);
+ Param->setExplicitObjectParameterLoc(SourceLocation());
+ }
+
// Do not add 'void' to the list.
break;
}
diff --git a/clang/test/CXX/drs/cwg29xx.cpp b/clang/test/CXX/drs/cwg29xx.cpp
index ca598bb39a6c31..e55e8e35e86f28 100644
--- a/clang/test/CXX/drs/cwg29xx.cpp
+++ b/clang/test/CXX/drs/cwg29xx.cpp
@@ -6,6 +6,14 @@
// RUN: %clang_cc1 -std=c++23 -pedantic-errors -verify=expected %s
// RUN: %clang_cc1 -std=c++2c -pedantic-errors -verify=expected %s
+namespace cwg2915 { // cwg2915: 20 tentatively ready 2024-08-16
+#if __cplusplus >= 202302L
+struct A {
+ void f(this void); // expected-error {{explicit object parameter cannot have 'void' type}}
+};
+#endif
+}
+
namespace cwg2917 { // cwg2917: 20 review 2024-07-30
template <typename>
class Foo;
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 71185b021def3d..e5c5e50104fdaf 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -17346,7 +17346,11 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td><a href="https://cplusplus.github.io/CWG/issues/2915.html">2915</a></td>
<td>tentatively ready</td>
<td>Explicit object parameters of type <TT>void</TT></td>
- <td align="center">Not resolved</td>
+ <td align="center">
+ <details>
+ <summary>Not resolved</summary>
+ Clang 20 implements 2024-08-16 resolution
+ </details></td>
</tr>
<tr class="open" id="2916">
<td><a href="https://cplusplus.github.io/CWG/issues/2916.html">2916</a></td>
More information about the cfe-commits
mailing list