Skip to content

[Clang] Reject this void explicit object parameters (CWG2915) #108817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 17, 2024

Conversation

MitalAshok
Copy link
Contributor

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)

@MitalAshok MitalAshok requested a review from Endilll as a code owner September 16, 2024 12:03
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Sep 16, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 16, 2024

@llvm/pr-subscribers-clang

Author: Mital Ashok (MitalAshok)

Changes

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)


Full diff: https://github.com/llvm/llvm-project/pull/108817.diff

5 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+3)
  • (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+2)
  • (modified) clang/lib/Sema/SemaType.cpp (+8)
  • (modified) clang/test/CXX/drs/cwg29xx.cpp (+8)
  • (modified) clang/www/cxx_dr_status.html (+63-5)
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 <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 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 <typename>
 class Foo;
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index f036fc5add2413..127bfe7e0e3724 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -11809,11 +11809,11 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
     <td>Reference list-initialization ignores conversion functions</td>
     <td align="center">Not resolved</td>
   </tr>
-  <tr class="open" id="1997">
+  <tr id="1997">
     <td><a href="https://cplusplus.github.io/CWG/issues/1997.html">1997</a></td>
-    <td>drafting</td>
+    <td>DRWP</td>
     <td>Placement new and previous initialization</td>
-    <td align="center">Not resolved</td>
+    <td class="unknown" align="center">Unknown</td>
   </tr>
   <tr id="1998">
     <td><a href="https://cplusplus.github.io/CWG/issues/1998.html">1998</a></td>
@@ -17346,11 +17346,15 @@ <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>
-    <td>tentatively ready</td>
+    <td>review</td>
     <td>Variable template partial specializations should not be declared <TT>static</TT></td>
     <td align="center">Not resolved</td>
   </tr>
@@ -17427,6 +17431,60 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
     <td>open</td>
     <td>Unclear status of translation unit with <TT>module</TT> keyword</td>
     <td align="center">Not resolved</td>
+  </tr>
+  <tr class="open" id="2928">
+    <td><a href="https://cplusplus.github.io/CWG/issues/2928.html">2928</a></td>
+    <td>open</td>
+    <td>No ordering for initializing thread-local variables</td>
+    <td align="center">Not resolved</td>
+  </tr>
+  <tr class="open" id="2929">
+    <td><a href="https://cplusplus.github.io/CWG/issues/2929.html">2929</a></td>
+    <td>open</td>
+    <td>Lifetime of trivially-destructible static or thread-local objects</td>
+    <td align="center">Not resolved</td>
+  </tr>
+  <tr class="open" id="2930">
+    <td><a href="https://cplusplus.github.io/CWG/issues/2930.html">2930</a></td>
+    <td>open</td>
+    <td>Unclear term "copy/move operation" in specification of copy elision</td>
+    <td align="center">Not resolved</td>
+  </tr>
+  <tr class="open" id="2931">
+    <td><a href="https://cplusplus.github.io/CWG/issues/2931.html">2931</a></td>
+    <td>open</td>
+    <td>Restrictions on operator functions that are explicit object member functions</td>
+    <td align="center">Not resolved</td>
+  </tr>
+  <tr class="open" id="2932">
+    <td><a href="https://cplusplus.github.io/CWG/issues/2932.html">2932</a></td>
+    <td>open</td>
+    <td>Value range of empty enumeration</td>
+    <td align="center">Not resolved</td>
+  </tr>
+  <tr class="open" id="2933">
+    <td><a href="https://cplusplus.github.io/CWG/issues/2933.html">2933</a></td>
+    <td>open</td>
+    <td>Dangling references</td>
+    <td align="center">Not resolved</td>
+  </tr>
+  <tr class="open" id="2934">
+    <td><a href="https://cplusplus.github.io/CWG/issues/2934.html">2934</a></td>
+    <td>open</td>
+    <td>Unclear semantics of exception escaping from <TT>unhandled_exception</TT></td>
+    <td align="center">Not resolved</td>
+  </tr>
+  <tr class="open" id="2935">
+    <td><a href="https://cplusplus.github.io/CWG/issues/2935.html">2935</a></td>
+    <td>open</td>
+    <td>Destroying the coroutine state when initial-await-resume-called is false</td>
+    <td align="center">Not resolved</td>
+  </tr>
+  <tr class="open" id="2936">
+    <td><a href="https://cplusplus.github.io/CWG/issues/2936.html">2936</a></td>
+    <td>open</td>
+    <td>Local classes of templated functions should be part of the current instantiation</td>
+    <td align="center">Not resolved</td>
   </tr></table>
 
 </div>

@MitalAshok MitalAshok changed the title [Clang] Reject "this void" (CWG2915) [Clang] Reject this void explicit object parameters (CWG2915) Sep 16, 2024
Copy link
Contributor

@Endilll Endilll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but it would be nice for @cor3ntin to rubber-stamp it before merging.

Copy link
Contributor

@cor3ntin cor3ntin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but it would be nice to do the other changes to cxx_dr_status as a separate (NFC) commit

@shafik
Copy link
Collaborator

shafik commented Sep 16, 2024

LGTM but it would be nice to do the other changes to cxx_dr_status as a separate (NFC) commit

We should always strive to keep unrelated changes separate. There are a lot of good reasons for this. The most basic is that if we have to revert then we lose both set of changes but clearly the unrelated DR documentation changes are NFC.

@MitalAshok
Copy link
Contributor Author

@shafik: Since this is a generated file, it is very easy to regenerate after a revert with python3 clang/www/make_cxx_dr_status && git commit -am '[Clang][NFC] Update cxx_dr_status.html'

@Endilll: I've removed the other changes from cxx_dr_status.html manually from this commit. Can you create the separate patch to add the new cwg issues? Thanks!

@Endilll
Copy link
Contributor

Endilll commented Sep 17, 2024

@Endilll: I've removed the other changes from cxx_dr_status.html manually from this commit. Can you create the separate patch to add the new cwg issues? Thanks!

Pushed 88a9bca

@cor3ntin cor3ntin merged commit 09284e7 into llvm:main Sep 17, 2024
9 checks passed
hamphet pushed a commit to hamphet/llvm-project that referenced this pull request Sep 18, 2024
…#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)
tmsri pushed a commit to tmsri/llvm-project that referenced this pull request Sep 19, 2024
…#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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants