Skip to content

Commit 09284e7

Browse files
authored
[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)
1 parent fd26f84 commit 09284e7

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ Resolutions to C++ Defect Reports
170170
in constant expressions. These comparisons always worked in non-constant expressions.
171171
(`CWG2749: Treatment of "pointer to void" for relational comparisons <https://cplusplus.github.io/CWG/issues/2749.html>`_).
172172

173+
- Reject explicit object parameters with type ``void`` (``this void``).
174+
(`CWG2915: Explicit object parameters of type void <https://cplusplus.github.io/CWG/issues/2915.html>`_).
175+
173176
C Language Changes
174177
------------------
175178

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4687,6 +4687,8 @@ def err_void_only_param : Error<
46874687
"'void' must be the first and only parameter if specified">;
46884688
def err_void_param_qualified : Error<
46894689
"'void' as parameter must not have type qualifiers">;
4690+
def err_void_explicit_object_param : Error<
4691+
"explicit object parameter cannot have 'void' type">;
46904692
def err_ident_list_in_fn_declaration : Error<
46914693
"a parameter list without types is only allowed in a function definition">;
46924694
def ext_param_not_declared : ExtWarn<

clang/lib/Sema/SemaType.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5166,6 +5166,14 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
51665166
if (ParamTy.hasQualifiers())
51675167
S.Diag(DeclType.Loc, diag::err_void_param_qualified);
51685168

5169+
// Reject, but continue to parse 'float(this void)' as
5170+
// 'float(void)'.
5171+
if (Param->isExplicitObjectParameter()) {
5172+
S.Diag(Param->getLocation(),
5173+
diag::err_void_explicit_object_param);
5174+
Param->setExplicitObjectParameterLoc(SourceLocation());
5175+
}
5176+
51695177
// Do not add 'void' to the list.
51705178
break;
51715179
}

clang/test/CXX/drs/cwg29xx.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
// RUN: %clang_cc1 -std=c++23 -pedantic-errors -verify=expected %s
77
// RUN: %clang_cc1 -std=c++2c -pedantic-errors -verify=expected %s
88

9+
namespace cwg2915 { // cwg2915: 20 tentatively ready 2024-08-16
10+
#if __cplusplus >= 202302L
11+
struct A {
12+
void f(this void); // expected-error {{explicit object parameter cannot have 'void' type}}
13+
};
14+
#endif
15+
}
16+
917
namespace cwg2917 { // cwg2917: 20 review 2024-07-30
1018
template <typename>
1119
class Foo;

clang/www/cxx_dr_status.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17346,7 +17346,11 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
1734617346
<td><a href="https://cplusplus.github.io/CWG/issues/2915.html">2915</a></td>
1734717347
<td>tentatively ready</td>
1734817348
<td>Explicit object parameters of type <TT>void</TT></td>
17349-
<td align="center">Not resolved</td>
17349+
<td align="center">
17350+
<details>
17351+
<summary>Not resolved</summary>
17352+
Clang 20 implements 2024-08-16 resolution
17353+
</details></td>
1735017354
</tr>
1735117355
<tr class="open" id="2916">
1735217356
<td><a href="https://cplusplus.github.io/CWG/issues/2916.html">2916</a></td>

0 commit comments

Comments
 (0)