diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 485b75049927fe..9c87a0d002b4ac 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 `_). +- Reject explicit object parameters with type ``void`` (``this void``). + (`CWG2915: Explicit object parameters of type void `_). + C Language Changes ------------------ diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index d42558d2223aae..271f96e383e57d 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 e627fee51b66b8..7b99f5d13463fe 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 class Foo; diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html index f036fc5add2413..2ac5297aa1f33c 100755 --- a/clang/www/cxx_dr_status.html +++ b/clang/www/cxx_dr_status.html @@ -17346,7 +17346,11 @@

C++ defect report implementation status

2915 tentatively ready Explicit object parameters of type void - Not resolved + +
+ Not resolved + Clang 20 implements 2024-08-16 resolution +
2916