Skip to content

Commit

Permalink
[Clang] Reject this void explicit object parameters (CWG2915) (#108817
Browse files Browse the repository at this point in the history
)

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)
  • Loading branch information
MitalAshok authored Sep 17, 2024
1 parent fd26f84 commit 09284e7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------

Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down
8 changes: 8 additions & 0 deletions clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions clang/test/CXX/drs/cwg29xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion clang/www/cxx_dr_status.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 09284e7

Please sign in to comment.